我现在这样配置没有问题,你可以参考一下:
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
proxy_pass http://127.0.0.1:8090;
expires 30d;
access_log off;
}
location / {
proxy_pass http://127.0.0.1:8090;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
CORS 相关设置
add_header 'Access-Control-Allow-Origin' 'http://nginx-domain.com';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
client_max_body_size 200M; # 允许上传最大200MB的文件
client_body_temp_path /tmp/nginx-client-body 1 2;
proxy_read_timeout 120; # 设置超时时间为 120 秒
禁用代理缓冲,适用于 WebSocket 等需要升级的协议
proxy_buffering off;
缓冲区设置
proxy_buffers 16 16k;
proxy_buffer_size 64k;
使用 HTTP/1.1
proxy_http_version 1.1;
用于 WebSocket 升级
proxy_cache_bypass $http_upgrade;
}