Last active
September 6, 2018 17:08
-
-
Save charlesthk/bad9742a9af89b449d836dcd165200f9 to your computer and use it in GitHub Desktop.
Nginx HTTP conf for Django (https://medium.com/@charlesthk/deploy-nginx-django-uwsgi-on-aws-ec2-amazon-linux-517a683163c6)
This file contains hidden or 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
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