NGINX Cors 允许来源不匹配来源

NGINX Cors 允许来源不匹配来源

我的网站遇到了一个大问题。

自从我从 Apache 网络服务器迁移到 Nginx 后,我网站上的广告就不再起作用了。

我在 nginx 的网站配置文件中添加了以下几行:

add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Origin,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, HEAD' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Max-Age' '1728000' always;

我重新加载了 nginx,但什么也没发生。

我使用 curl -X OPTIONS -i 进行了测试https://xy.hu 答案是:

HTTP/1.1 405 Not Allowed
Server: nginx
Date: Mon, 05 Jul 2021 11:14:07 GMT
Content-Type: text/html
Content-Length: 150
Connection: keep-alive
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-XSS-protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
Feature-Policy: autoplay 'none'; camera 'none'
Referrer-Policy: same-origin
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Accept,Authorization,Origin,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, HEAD
Access-Control-Expose-Headers: Content-Length,Content-Range
Access-Control-Allow-Credentials: true
Access-Control-Max-Age: 1728000
<html>
<head><title>405 Not Allowed</title></head>
<body>
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx</center>
</body>
</html>

相关内容