開啟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';
中之後 '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教學有興趣的朋友有幫助。