I have a Django One Click Install Image VPS on Ubuntu 14.04 and have a site running which has minimal traffic. I need to host another independent Django website on it. As I am new to webserver configuration. Could Someone please guide me through the NGINX and Gunicorn Upstart configuration to host multiple sites. Consider my Sites are: www.mysite1.com www.mysite2.com I have already referred the questions:
But it does not mention the NINX and Gunicorn configuration to serve 2 independent websites on the same server.
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.
Refer to this article for the specifics on how the the Django one-click app is configured:
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.
The one-click install for Ubuntu 16.04 is set-up a little differently. I do not see a gunicorn.conf file in etc/init directory and the app_server section of the settings file points to a gunicorn.socket file.
I’m lost. How do I setup multiple django sites using the Ubuntu 16 one-click install option?
This comment has been deleted
Hi After setting up the new site. When I try to restart nginx server. I get following error
Is there any thing else to modify ?
To fix the
a duplicate default server for 0.0.0.0:80
just remove the default_server
in your second website, your need just one default_server
How would we host a second site in OneClickInstallation if its settings are based on Virtual environment. Settings explained here are without virtualenv.