想要节省流量和加快速度,但是发现在 nginx 服务器上,流入流量要比流出高出 2-4 倍。 反代其他网站也是,怀疑是后端( google 等)的响应没有 gzip ?但是我请求是带了 gzip 啊,这是我的配置:
worker_processes 1;
error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid;
worker_rlimit_nofile 1024; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
keepalive_timeout 120;
gzip on;
gzip_types application/json text/plain application/x-javascript application/javascript text/javascript text/css application/xml text/xml;
gzip_min_length 1k;
server_tokens off;
upstream backend{
server google.com;
keepalive 120;
}
proxy_temp_path /tmp/cache_tmp;
proxy_cache_path /tmp/cache levels=1:2 keys_zone=cache1:100m inactive=20m max_size=5g;
server{
listen 80;
location / {
proxy_pass https://backend;
proxy_http_version 1.1;
proxy_set_header Range $http_range;
proxy_set_header If-Range $http_if_range;
proxy_set_header Connection "";
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Accept-Encoding "gzip";
proxy_cache cache1;
proxy_cache_key $uri$is_args$args;
proxy_cache_revalidate on;
}
}
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.