nginx 配置ajax跨域访问php api
程序员文章站
2022-04-03 18:27:41
...
打开nginx的配置文件nginx.conf,在server中配置一下:
#try_files $uri =404;
#handel cosr by mao
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'OPTION, POST, GET';
add_header 'Access-Control-Allow-Headers' 'X-Requested-With, Content-Type';
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
location ~ \.php?($|/)
{#try_files $uri =404;
#handel cosr by mao
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'OPTION, POST, GET';
add_header 'Access-Control-Allow-Headers' 'X-Requested-With, Content-Type';
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
以上就介绍了nginx 配置ajax跨域访问php api,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
上一篇: linux如何挂载硬盘
下一篇: php怎么删除自身