Skip to content

Instantly share code, notes, and snippets.

@jhcao23
Last active November 25, 2017 22:41
Show Gist options
  • Save jhcao23/646ef19056137d35ab74bcac8e26dcf7 to your computer and use it in GitHub Desktop.
Save jhcao23/646ef19056137d35ab74bcac8e26dcf7 to your computer and use it in GitHub Desktop.
nginx wide open CORS OPTIONS config
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE';
#
# Custom headers and headers various browsers *should* be OK with but aren't
#
add_header 'Access-Control-Allow-Headers' 'Authorization,X-AUTH-TOKEN,error,DNT,Access-Control-Allow-Origin,Access-Control-Allow-Methods,Access-Control-Allow-Headers,Access-Control-Allow-Credentials,Keep-Alive,User-Agent,X-Requested-With,Last-Modified,If-Modified-Since,Cache-Control,Content-Type,Content-Language,Content-Range,Range,Pragma,Expires';
#
# Tell client that this pre-flight info is valid for 20 days
#
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_pass http://localhost:8443;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment