ssl 没有“Access-Control-Allow-Origin”标头错误,但它可用

uqjltbpv  于 2022-11-14  发布在  其他
关注(0)|答案(1)|浏览(128)

我用nginx创建了一个代理服务器。我用Certbot安装了SSL证书。安装SSL后,我在前端收到No 'Access-Control-Allow-Origin' header错误。我在.conf文件中添加了add_header 'Access-Control-Allow-Origin' '*'命令。但我一直收到相同的错误。

错误:Access to fetch at 'https://api.mywebsite.com/api/users' from origin 'https://panel.mywebsite.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
我的前端网站:https://panel.mywebsite.com我的后端网站:https://api.mywebsite.com
#/etc/nginx/已启用站点/api.mywebsite.com

server {

    server_name api.mywebsite.com;
    add_header Access-Control-Allow-Origin https://panel.mywebsite.com;

    location / {
            proxy_pass http://localhost:1337;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_redirect off;
     }

    listen [::]:443 ssl; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/api.mywebsite.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/api.mywebsite.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = api.mywebsite.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    listen [::]:80;

    server_name api.mywebsite.com;
    return 404; # managed by Certbot

}

#/etc/nginx/已启用站点/panel.mywebsite.com

server {

    server_name panel.mywebsite.com;

    location / {
            proxy_pass http://127.0.0.1:3000;
            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_redirect off;
     }

    listen [::]:443 ssl; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/panel.mywebsite.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/panel.mywebsite.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = panel.mywebsite.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    listen [::]:80;

    server_name panel.mywebsite.com;
    return 404; # managed by Certbot

}
mzsu5hc0

mzsu5hc01#

我修复了这个问题。虽然CORS错误发生了,但是当我详细检查错误时,我意识到这个问题不是由CORS引起的,而是由于最大车身尺寸值不足。在增加client_max_body_size之后,问题解决了。
413 Request Entity Too Large - File Upload Issue

相关问题