Created
April 29, 2020 06:38
-
-
Save koepnick/576c740ccdcf093465098803fea91e87 to your computer and use it in GitHub Desktop.
NGINX Boilerplate - Django/JS Frontend
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
# A fully working dev example | |
# This assumes that: | |
# A (in my case Vue) JS dev server is listening on port :8080 and is in charge of all look and feel loveliness | |
# it also assumes that a Django dev server is running on port :8000 and has the sole purpose of being an API server | |
# The websockets stanza can be omitted if it isn't applicable | |
# Any documents in /static will be served...well statically | |
# `manage.py collectstatic` *should* copy the Django static files here so long as: | |
# STATIC_FILES = '/static/' | |
# STATICFILES_DIRS = ['/srv/static'] | |
# is configured in settings.py | |
server { | |
listen 80; | |
server_name some.advancedsite.com; | |
location /static/ { | |
autoindex on; | |
root /srv/static/; | |
} | |
location / { | |
proxy_pass http://localhost:8080; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-Host $host; | |
proxy_set_header X-Forwarded-Server $host; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
proxy_set_header X-Forwarded-For $remote_addr; | |
proxy_redirect off; | |
} | |
location /api/ { | |
proxy_pass http://localhost:8000; | |
uwsgi_modifier1 30; | |
} | |
location /sockjs-node/ { | |
proxy_pass http://localhost:8080; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "Upgrade"; | |
} | |
} |
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
# Both of these exmaples presume a working instance of NGINX on a Linux server | |
# Docker should be fine | |
# Certbot should be used, even in development | |
# If you're using Windows for any of this...well you've got bigger problems than TCP packets and load balancing. | |
# The barest minimum | |
server { | |
include uwsgi_params; | |
root /var/www/html; | |
index index.html index.htm index.nginx-debian.html; | |
server_name some.coolsite.com; | |
location / { | |
# This is for the dev server only! | |
proxy_pass django; | |
# For uWSGI... | |
# uwsgi_pass django; | |
} | |
} | |
upstream django { | |
server localhost:8000; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment