想要节省流量和加快速度,但是发现在 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;
}
}
}