Skip to content

Instantly share code, notes, and snippets.

@charlesthk
Last active September 6, 2018 17:08
Show Gist options
  • Save charlesthk/bad9742a9af89b449d836dcd165200f9 to your computer and use it in GitHub Desktop.
Save charlesthk/bad9742a9af89b449d836dcd165200f9 to your computer and use it in GitHub Desktop.
server {
listen 80;
server_tokens off;
server_name www.my-website.com;
return 301 http://my-website.com$request_uri;
}
server {
listen 80;
server_name my-website.com;
client_max_body_size 10M;
access_log /var/log/my-website.com.access.log;
error_log /var/log/my-website.com.error.log;
# -------------
# Handle Django
# -------------
location / {
proxy_pass http://localhost:8000;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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-Proto $scheme;
}
# ------------------
# serve static files
# ------------------
# here we assume the STATIC_ROOT inside your django project is
# set to /static/
location /static/ {
alias /home/ec2-user/django/static/;
}
# -----------
# Enable GZIP
# -----------
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_types text/plain
text/css
application/json
application/javascript
application/x-javascript
text/xml
application/xml
application/xml+rss
text/javascript
image/svg+xml;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.0;
# ------------
# Cache assets
# ------------
location ~* .(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css
|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz
|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi
|wav|bmp|rtf)$ {
expires max;
log_not_found off;
access_log off;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment