Skip to content

Instantly share code, notes, and snippets.

@ben

ben/nginx.conf Secret

Created January 26, 2016 15:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ben/912ba9484b0ff825acd3 to your computer and use it in GitHub Desktop.
Save ben/912ba9484b0ff825acd3 to your computer and use it in GitHub Desktop.
Production NGINX configuration for serving from Cloudfront
worker_processes 4;
events { worker_connections 1024; }
# proxy API to API server so cross-domain requests aren't required
# proxy all others to S3 bucket hosted assets
http {
client_max_body_size 10M;
access_log off;
error_log /dev/stdout;
upstream api {
server api:8000;
}
gzip on;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_proxied any;
# Always redirect to https
server {
server_name _;
listen 80;
return 301 https://$host$request_uri;
}
server {
listen 443;
server_name *.domain.tld;
rewrite_log on;
# /api to api container
location /api {
proxy_pass http://api;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
# everything else to index.html in s3 bucket
location /index.html {
proxy_ignore_headers set-cookie;
proxy_hide_header set-cookie;
proxy_set_header cookie "";
# avoid passing along amazon headers
# http://docs.aws.amazon.com/AmazonS3/latest/API/RESTCommonResponseHeaders.html
proxy_hide_header x-amz-delete-marker;
proxy_hide_header x-amz-id-2;
proxy_hide_header x-amz-request-id;
proxy_hide_header x-amz-version-id;
proxy_pass http://s3-us-west-1.amazonaws.com/my-bucket/index.html;
}
location / {
rewrite ^ /index.html;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment