Created
February 7, 2017 10:03
-
-
Save nix1947/e95a2e250fd34c1ab6b3268f5da6ab55 to your computer and use it in GitHub Desktop.
nginx configuration for django
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
upstream example { | |
# fail_timeout=0 means we always retry an upstream even if it failed | |
# to return a good HTTP response (in case the Unicorn master nukes a | |
# single worker for timing out). | |
server unix:/webapps/example.com/gunicorn.sock fail_timeout=0; | |
} | |
server{ | |
listen 80; | |
server_name example.com; | |
client_max_body_size 4G; | |
access_log /webapps/example.com/logs/nginx-access.log; | |
error_log /webapps/example.com/logs/nginx-error.log; | |
# Robot.txt configuration | |
# developers work on robot.txt more so it is suitable to push inside source code. | |
location /robots.txt { | |
alias /webaps/example.org/robots.txt; | |
} | |
# Static assets configuration | |
location /static/ { | |
alias /webapps/example.com/master/src/assets/; | |
expires 30d; | |
} | |
# Media configuration | |
location /media/ { | |
alias /webapps/example.com/master/src/media/; | |
expires 30d; | |
} | |
# Need to review | |
location / { | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_redirect off; | |
if (!-f $request_filename) { | |
proxy_pass http://example; #app name | |
break; | |
} | |
} | |
# Favicon configuration | |
location /favicon.ico { | |
alias /webapps/example.com/master/src/assets/img/favicon.ico; | |
} | |
# Prevent hidden files being serverd | |
location ~ /\. { access_log off; log_not_found off; deny all; } | |
# Error page configuration | |
error_page 500 502 503 504 /500.html; | |
location = /500.html { | |
root /webapps/example.com/master/src/static/; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment