我正在运行the official nginx alpine 1.17.1 image。
nginx.config:
http {
include /etc/nginx/mime.types;
index index.html;
server {
root /opt/myapp/wwwroot;
listen 80;
# enable gzip compression for content 1KB and over
gzip on;
gzip_comp_level 2;
gzip_min_length 1000;
# supposed to be the default but whether or not
# I add this line, the response from the proxied request
# still gets compressed
gzip_proxied off;
gzip_types text/plain application/x-javascript text/xml text/css application/xml application/json;
location /api/ {
# this only way to disable gzip is for me to uncomment the line below
# gzip off;
proxy_pass https://api.example.com/
}
}
}
假设nginx在http://localhost:3000上运行,并且上游服务器从https://api.example.com/foo返回未压缩的JSON内容,则对http://localhost:3000/api/foo的HTTP请求将返回nginx压缩的内容。
我希望nginx不会压缩响应,因为它已被代理到https://api.example.com。
配置错误还是我误解了gzip_proxied?