Skip to content

Instantly share code, notes, and snippets.

@seanmavley
Created April 29, 2015 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanmavley/4076fe6908b0c9b89dcb to your computer and use it in GitHub Desktop.
Save seanmavley/4076fe6908b0c9b89dcb to your computer and use it in GitHub Desktop.
Simulate Production Server on Local PC, Django-Nginx
First all, have DEBUG = True in your settings.py
Nginx should be installed. After nginx install, restart PC, if not already.
Create a new file in /etc/nginx/sites-available/<file_name>
Put in this. I called mine noodles
/etc/nginx/sites-available/noodles
upstream app_server {
server 127.0.0.1:8000 fail_timeout=0;
}
server {
listen 8001;
# listen [::]:80 ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
client_max_body_size 4G;
server_name localhost:8000;
keepalive_timeout 5;
# Your Django project's media files - amend as required
location /media {
alias /home/noodle/media;
}
location /static {
# this goes to directly static of my local project
# you must have STATIC_ROOT='static' in your settings.py
# and must have run python manage.py collectstatic
alias /home/khophi/Developments/DjangoApps/Noodles/static;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
In django project root, run python manage.py runserver
That should hook your django to port 8000. Nginx listens on port 8000 for requests but serves then on port 8001.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment