我的 nginx 配置中有以下内容:
location / {
# CORS
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST' always;
proxy_pass http://localhost:8080/guacamole/; # systemd: tomcat9
proxy_buffering off;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_cookie_path /guacamole/ /;
access_log off;
}
当我POST
向服务器发送请求时,Access-Control-Allow-Origin
响应中没有标头GET
。但是,当我发送请求时,标头却出现了。知道为什么吗?
答案1
我似乎认为代理覆盖了Access-Control-Allow-Origin
响应中的标头。我通过添加以下内容解决了此问题always
:
# CORS
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST' always;