Nginx

使用 POST 請求時,Access-Control-Allow-Origin 標頭不包含在響應中

  • April 8, 2020

我的 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請求時。任何想法為什麼?

我似乎代理覆蓋Access-Control-Allow-Origin了響應中的標頭。我通過添加解決了這個問題always

   # CORS
   add_header 'Access-Control-Allow-Origin' '*' always;
   add_header 'Access-Control-Allow-Methods' 'GET, POST' always;

引用自:https://serverfault.com/questions/1011514