Skip to content

Instantly share code, notes, and snippets.

@hardboiled
Created June 7, 2022 20:34
Show Gist options
  • Save hardboiled/fea8edf7aa38c0b543c10a81acb4f420 to your computer and use it in GitHub Desktop.
Save hardboiled/fea8edf7aa38c0b543c10a81acb4f420 to your computer and use it in GitHub Desktop.
base nginx cors config I copied somewhere for local dev
add_header 'Access-Control-Allow-Origin' 'http://localhost:3000' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range' always;
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH' always;
@hardboiled
Copy link
Author

Example use:

# default.conf.template
server {
    listen 80 default_server;
    server_name _;
    server_name_in_redirect off;
    access_log  /var/log/nginx/access.log;
    error_log  /var/log/nginx/error.log debug;
    location /dev {
        include /etc/nginx/conf.d/corsheaders.conf;
        rewrite /dev/(.*) /$1  break;
        proxy_pass http://host.docker.internal:5000;
    }
#     location /qa {
#         rewrite /foo/(.*) /$1  break;
#         include /etc/nginx/conf.d/corsheaders.conf;
#         proxy_pass https://<qa-url>;
#     }
#     location /production {
#         rewrite /foo/(.*) /$1  break;
#         include /etc/nginx/conf.d/corsheaders.conf;
#         proxy_pass http://<prod-url>;
#     }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment