Nginx 反代无法返回 304,求助

2016-03-10 09:48:33 +08:00
 longkas

最近发现网上没有反代 Google 的 gstatic.com 的站点,自己又会用到相关服务,于是尝试用 Nginx 反代,参考了 ttt.tt 反代的教程,现在可以反代成功,但是每次都要重新获取很烦。反复实验了几种参数,都无法使 Nginx 告知浏览器 304 返回值。求助大家看一下,
试验链接: http://gstatic.178.re/charts/loader.js
这是 Nginx 的配置

https://gist.github.com/Archieeeeee/b27a46b62775fb188c07

3429 次点击
所在节点    NGINX
2 条回复
longkas
2016-03-10 10:00:35 +08:00
不会贴代码 还不能编辑了
upstream gstatic {
server www.gstatic.com;
}

proxy_buffering on;
etag on;
proxy_temp_file_write_size 1024k;
proxy_temp_path /var/cache/nginx/temp;
proxy_cache_path /var/cache/nginx/cache levels=1:2 keys_zone=cache_one:100m inactive=19d max_size=5g;

server {
listen 80;

server_name gstatic.178.re;

resolver 8.8.8.8;

location / {
sub_filter "www.gstatic.com" "gstatic.178.re";
sub_filter "https" "http";
sub_filter_once off;
sub_filter_types *;
proxy_pass_header Server;
proxy_set_header Host www.gstatic.com;
proxy_set_header Accept-Encoding '';
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://gstatic;
proxy_cache cache_one;
proxy_cache_valid 200 304 365d;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_min_uses 1;
expires max;
proxy_cache_revalidate on;
add_header X-Proxy-Cache $upstream_cache_status;
add_header Cache-Control "public";
if_modified_since before;
}


}
int64ago
2016-03-10 10:16:14 +08:00

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/262403

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX