Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nginx example of using CORS
upstream mycoolapp {
server unix:///var/run/puma.sock;
}
server {
listen 80;
server_name www.my-cool-website.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name www.my-cool-website.com;
root /app/public;
ssl_certificate /shared/certs/ssl.crt;
ssl_certificate_key /shared/certs/ssl.key;
client_max_body_size 20m;
location / {
add_header 'Access-Control-Allow-Origin' '*'; # change this to more strict CDN host. e.g.: 'xxxxxxxxxxxxxx.cloudfront.net'
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header Client-IP $remote_addr;
proxy_pass http://mycoolapp;
}
}
@equivalent

This comment has been minimized.

Copy link
Owner Author

@equivalent equivalent commented Oct 3, 2016

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