Question

How do I setup multiple Django sites using the One-Click install option for Ubuntu 16.04

I have successfully created the one-click Django droplet and the website works but I am unsure how to add other Django websites.

This is the process I have taken so far:

  1. I copied the default django_project folder in /home/django and renamed it.

  2. I copied the file in etc/nginx/sites-available and created the sym-link in etc/nginx/sites-enabled

  3. I then updated that file with the following:

upstream newsite_app_server {
    server unix:/home/django/gunicorn.socket fail_timeout=0;
}

server {
    listen 80;
    listen [::]:80;

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

    client_max_body_size 4G;
    server_name newsite.com www.newsite.com;

    keepalive_timeout 5;

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

    # your Django project's static files - amend as required
    location /static {
        alias /home/django/newsite/django_project/static;
    }

    # Proxy the static assests for the Django Admin panel
    location /static/admin {
       alias /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/;
    }

    location / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_redirect off;
            proxy_buffering off;

            proxy_pass http://newsite_app_server;
    }

}
  1. I restarted the server but then received an error about DisallowedHost, so I then added the domain name to the Allowed_Host line in the settings.py file, restarted Nginx and Gunicorn and still got the same error. I tried using the wildcard [‘*’] with no luck.

Am I missing something? It seems as though I should create some other instance of gunicorn but I’m not sure.

I tried to follow the instructions for setting up multiple Django sites for Ubuntu 14.04 at the following link but the settings seem a little different compared to version 16.04: https://www.digitalocean.com/community/questions/setup-multiple-django-websites-on-django-one-click-install-image-vps


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

I found the solution:

  • I created a new gunicorn service at - /etc/systemd/system/
[Unit]
Description=Gunicorn daemon for Django Project
Before=nginx.service
After=network.target

[Service]
WorkingDirectory=/home/django/django_project
ExecStart=/usr/bin/gunicorn --name="YOUR PROJECT NAME" --pythonpath=/home/django/"YOUR PROJECT NAME"  --bind unix:/home/django/"New socket: ie: gunicorn2.socket" --config /etc/gunicorn.d/gunicorn.py django_project.wsgi:application
Restart=always
SyslogIdentifier=gunicorn
User=django
Group=django


[Install]
WantedBy=multi-user.target

After that start the new service and the new socket, in the example gunicorn2.socket, will be created. - service gunicorn2 start Set the nginx conf with the second upstream calling to this new socket - upstream newsite_app_server { server unix:/home/django/gunicorn.socket2 fail_timeout=0; }

and restart nginx service.

That works for me. Hope to help.

I am having the same issue… Is there any solution?

Thx in advance.