这个应该是add_header无效导致的,nginx官方文档中说了,add_header必须在代理服务站点响应代码为 200、201 (1.3.10)、204、206、301、302、303、304、307 (1.1.16、1.0.13) 或 308 (1.13.0),则将指定字段添加到响应标头。其他情况不强制添加。
修复的办法就是加一个always
proxy_buffering off; if ($request_method = 'OPTIONS') { add_header Access-Control-Allow-Origin '*'; add_header 'Access-Control-Allow-Headers' 'authorization,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; return 204; } if ($request_method != 'OPTIONS') { add_header Access-Control-Allow-Origin '*' always; } proxy_pass https://backsercer/; proxy_set_header Host backsercer; proxy_ssl_server_name on;
网友回复