Setup Multiple Django Websites on Django One Click Install Image VPS

How To Use the Django One-Click Install Image

Copy the Nginx configuration for your new site:

cp /etc/nginx/sites-available/django /etc/nginx/sites-available/site2
ln -s /etc/nginx/sites-available/site2 /etc/nginx/sites-enabled/site2

Then edit its contents to match where you installed your new Django app:

upstream app_server {
    server 127.0.0.1:9500 fail_timeout=0;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.html index.htm;

    client_max_body_size 4G;
    server_name www.mysite2.com;

    keepalive_timeout 5;

    # Your Django project's media files - amend as required
    location /media  {
        alias /home/django/new_project/new_app/media;
    }

    # your Django project's static files - amend as required
    location /static {
        alias /home/django/new_project/new_app/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;
    }
}

Do the same for the Upstart script used to start gunicorn:

cp /etc/init/gunicorn.conf /etc/init/new_site.conf

And change the port and path for the project:

description "Gunicorn daemon for Django project"

start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]

# If the process quits unexpectedly trigger a respawn
respawn

setuid django
setgid django
chdir /home/django

exec gunicorn \
    --name=new_project \
    --pythonpath=new_project \
    --bind=0.0.0.0:9500 \
    --config /etc/gunicorn.d/gunicorn.py \
    django_project.wsgi:application

You should now be able to start your project with:

service nginx restart
service new_site start

Notice that the way you start the project is determined by the name you give the Upstart script.

Hope this points you in the right direction! Let us know how it goes.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s