我尝试了在线发布的样板“添加标头”的all,以及nginx-extras的“ set_more_headers”,都无济于事。我试过在服务器块和位置块中添加标头。依然没有。我想停止看到此错误:
无法加载https://example.com/api:在飞行前响应中,Access-Control-Allow-Headers不允许请求标头字段Access-Control-Allow-Origin。
这是nginx conf:
server {
server_name example.com www.example.com;
root /home/myname/src/clamsy/web;
access_log /home/myname/src/myapp/web/logs/nginx/access.log;
error_log /home/myname/src/myapp/web/logs/nginx/error.log;
location / {
add_header 'Access-Control-Allow-Origin' *;
include proxy_params;
proxy_pass http://unix:/home/myname/src/myapp/run/myapp.sock;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.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 = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name example.com www.example.com;
return 404; # managed by Certbot
}