Skip to content

Instantly share code, notes, and snippets.

@yzf
Created August 28, 2018 02:37
Show Gist options
  • Save yzf/8b9cddea55c15cba856877c34b7480c5 to your computer and use it in GitHub Desktop.
Save yzf/8b9cddea55c15cba856877c34b7480c5 to your computer and use it in GitHub Desktop.
nginx跨域
server {
listen 80 default_server;
index index.html index.htm index.nginx-debian.html;
location /api {
proxy_pass http://127.0.0.1:8080;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
if ($request_method = 'OPTIONS') {
return 204;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment