I want to run two Django applications on the same server, with Nginx and Gunicorn. I can run them separately, but not both at the same time: When I try, one is OK, but for the other one I receive 502. Here are my configuration files:
First nginx config for the first project:
upstream app_server {
server 127.0.0.1:9000 fail_timeout=0;
}
server {
listen 80;
# listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
client_max_body_size 4G;
server_name domain1.com;
keepalive_timeout 5;
# Your Django project's media files - amend as required
location /media {
alias /home/django/domain1/media;
}
# your Django project's static files - amend as required
location /static {
alias /home/django/domain1/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;
}
}
And for the second django project:
upstream app_server_2 {
server 127.0.0.1:8000 fail_timeout=0;
}
server {
listen 80;
# listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
client_max_body_size 4G;
server_name domain2.com;
keepalive_timeout 5;
# Your Django project's media files - amend as required
location /media {
alias /home/django/domain2/media;
}
# your Django project's static files - amend as required
location /static {
alias /home/django/domain2/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_2;
}
}
And Gunicorn upstart script:
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=domain1 \
--pythonpath=domain1 \
--bind=127.0.0.1:9000 \
--config /etc/gunicorn.d/gunicorn.py \
domain1.wsgi:application
exec gunicorn \
--name=domain2 \
--pythonpath=domain2 \
--bind=127.0.0.1:8000 \
--config /etc/gunicorn.d/gunicorn.py \
domain2.wsgi:application
Any suggestions?
Update 24.01.2016
While I am debugging, I have separated Gunicorn upstart scripts into two (one for each project), and renamed them. I have figured out that I am getting 4 of the following error (2 for each, one for starting, one for stopping on Gunicorn daemon restart):
/etc/gunicorn.d/gunicorn.py:2: RuntimeWarning: Parent module '/etc/gunicorn.d/gunicorn' not found while handling absolute import
from os import environ
Here is my gunicorn.py:
"""gunicorn WSGI server configuration."""
from multiprocessing import cpu_count
from os import environ
def max_workers():
return cpu_count() * 2 + 1
max_requests = 1000
worker_class = 'gevent'
workers = max_workers()
0 Answers