【发布时间】:2016-07-07 10:12:43
【问题描述】:
我想用 Nginx 反向代理网站 www.gstatic.com。
- 使用站点 gstatic.178.re 反向代理 www.gstatic.com
- 替换资源中包含“www.gstaic.com”的内容,以便“gstatic.178.re”仍然可以处理进一步的请求。
基本上它有效,但如果我再次访问相同的链接,它不会返回 304。我在 Nginx 上启用了缓存,还尝试设置 etag 和 expires 属性。 这是我的 Nginx 配置,
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;
}
}
这是一个用于测试的示例链接:http://gstatic.178.re/charts/loader.js
【问题讨论】: