被CORS策略阻止:“控制-允许-起源”头包含多个值,带有PROXY服务器的NGINX

eh57zj3b  于 2023-11-17  发布在  Nginx
关注(0)|答案(1)|浏览(128)

当我在NGINX中添加一个单独的控制-允许-Origin头时,它有两个。当我删除add_header行时,没有。所以IDK是额外的起源被添加的地方。

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name service.alloy.love;
    root /var/www/cybers-cafe/cybers-cafe-service/system/nginx-root; # Used for acme.sh SSL verification (https://acme.sh)

    access_log /var/log/nginx/service.alloy.love/access.log;
    error_log /var/log/nginx/service.alloy.love/error.log;

    ssl_certificate /etc/letsencrypt/live/alloy.love/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/alloy.love/privkey.pem;

    include /etc/nginx/snippets/ssl-params.conf;

#    location /static/ {
#        alias /var/www/cybers-cafe/static/;
#        try_files $uri $uri/ =404;
#    }

    location / {
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $http_host;
        proxy_cache_bypass $http_upgrade;
        proxy_pass http://127.0.0.1:59595;
        add_header 'Access-Control-Allow-Origin' 'https://www.alloy.love';
    }

    location ~ /.well-known {
        allow all;
    }

    client_max_body_size 50m;
}

字符串
我试图删除

add_header 'Access-Control-Allow-Origin' 'https://www.alloy.love';


但正如我所说,它完全删除了标题。
我试着加上

proxy_hide_header Access-Control-Allow-Origin;


但这也完全去除了报头。

nfeuvbwi

nfeuvbwi1#

我也遇到了同样的问题,我修复了它,从请求的脚本中删除了"Access-Control-Allow-Origin"响应头,并将其仅保留为Nginx指令
在我的例子(pythonscript)中,我从BaseHTTPRequestHandler类的do_GETdo_OPTIONS方法中删除了:

# send_header("Access-Control-Allow-Origin", ...)

字符串

相关问题