给 PHP 接口弄了个站点配置,代码已经设置好跨域
如果是在 PC 端访问 https://domain.com/demo/
能访问,正常
但如果前端 用 ajax 请求 https://domain.com/demo/
报跨域错误:
Access to XMLHttpRequest at 'https://domain.com/demo/' from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
但奇怪的是代码不变,把接口地址改成具体的 php 文件地址如: https://domain.com/demo/index.php ,就正常了
站点配置:
server {
listen 80;
server_name _;
root /var/www;
index index.php index.html;
client_max_body_size 50m;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
charset utf-8;
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php:9000;
try_files $uri =404;
}
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.