-
-
Save ben/912ba9484b0ff825acd3 to your computer and use it in GitHub Desktop.
Production NGINX configuration for serving from Cloudfront
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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