phpstudy nginx设置CORS跨域不起作用的可能解决方法
今天搞了半天的跨域问题,想通过nginx配置跨域,希望以后本地调试程序都不用为这件事烦心。无非就是设置几个请求头: add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Methods *; add_header Access-Control-Allow-Headers *; 但是配置半天没配好,真的是半天。。后来配好了,在此分享给大家,希望给大家一点帮助。 请求PHP文件报错CORS 配置那三行,不能写在 localhost_80.conf 的 location / { #... } 里面,因为有反向代理!继续往下看这个文件,会看到 location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document