Gunicorn

sudo nano /opt/mysite/mysite/gunicorn_config.py:

command = '/opt/mysite/bin/gunicorn'
pythonpath = '/opt/mysite'
bind = 'test.com:8001'
workers = 5
user = 'YOUR_USERNAME'
autostart=True
autorestart=True
redirect_stderr=True

sudo nano /etc/init/gunicorn.conf

description "My Gunicorn"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
setuid YOUR_USERNAME
setgid YOUR_USERNAME
chdir /opt/mysite/mysite
exec /opt/mysite/bin/gunicorn --log-file gunicorn_error.log --log-level error -c gunicorn_config.py mysite.wsgi:application
#exec bin/gunicorn --workers 3 --bind unix:/opt/mysite/mysite.sock mysite.wsgi:application

Nginx

sudo nano /etc/nginx/sites-available/mysite

server {
 listen 80;
 server_name test.com;
access_log /opt/mysite/access.log;
 error_log /opt/mysite/error.log;
location /static/ {
 alias /opt/mysite/mysite/static/;
 }
 location /media/ {
 alias /opt/mysite/mysite/media/;
 }
location / {
 proxy_pass http://test.com:8001;
 proxy_set_header X-Forwarded-Host $server_name;
 proxy_set_header X-Real-IP $remote_addr;
 #proxy_pass http://unix:/opt/mysite/mysite.sock;
 #add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
 }
 }

cd /etc/nginx/sites-enabled

Once there, run this command:

sudo ln -s ../sites-available/mysite

Django

sudo nano /opt/mysite/mysite/mysite/wsgi.py

 

import os
import sys
import site
# Add the site-packages of the chosen virtualenv to work with
 site.addsitedir('/opt/mysite/lib/python3.4/site-packages')
# Add the app's directory to the PYTHONPATH
 sys.path.append('/opt/mysite/')
 sys.path.append('/opt/mysite/mysite')
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
 # Activate your virtual env
 activate_env = os.path.expanduser("/opt/mysite/bin/activate_this.py")
 exec(open(activate_env).read())
from django.core.wsgi import get_wsgi_application
 application = get_wsgi_application()

 

Ubuntu

sudo nano /etc/hosts

Add this line:

 127.0.0.1 test.com www.test.com

 

sudo service gunicorn restart

sudo service nginx restart

That’s it!