nginx配置跨域
最近老是遇到跨域问题,不想每次都去服务器上翻配置,现在记录下.
系统:centos 7.x(64位)
nginx配置:
server {
listen 80;
server_name ******.com;
access_log /data/nginx/logs/****.com_access.log main;
index index.html index.htm index.php;
root ******;
add_header Access-Control-Allow-Origin '*';
#add_header Access-Control-Allow-Origin $http_origin;
add_header Access-Control-Allow-Credentials 'true';
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'token,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,Lang';
add_header Access-Control-Expose-Headers 'Content-Length,Content-Range';
location / {
try_files $uri $uri/ /index.php?$args;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
.....
}
然后重启nginx就好了.
评论: