打开nginx的配置文件nginx.conf,在server中配置一下:
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教程有兴趣的朋友有所帮助。