0
votes

I have DjangoServer1 and DjangoServer2 running a virtualenv, where gunicorn is installed. nginx is installed under user in Ubuntu.

I make DjangoServer1 running under nginx, gunicorn.

Server IP: 12.12.12.12

Web site domain for DjangoServer1 is mydomain1.com

Web site domain for DjangoServer2 is mydomain2.com

This is nginx server config for DjangoServer1.

/etc/nginx/sites-available/DjangoServer1

server {
    listen 0.0.0.0:80;
    server_name 127.0.0.1;

    location = /favicon.ico { access_log off; log_not_found off; }

    location /static/ {
            root /home/user/develop/DjangoServer1;
    }

    location / {
            include proxy_params;
            proxy_pass http://unix:/home/user/develop/DjangoServer1/DjangoServer1.sock;
    }
}

I start the DjangoServer1:

1) Under virtualenv, run gunicorn command to start DjangoServer1

gunicorn --daemon --workers 3 --bind unix:/home/user/develop/DjangoServer1/DjangoServer1.sock DjangoServer1.wsgi

2) Then, run:

sudo service nginx restart

3) In router, I portforward port 80, 8000, to server 12.12.12.12

4) In browser, enter: 12.12.12.12. DjangoServer1 works. Enter: mydomain1.com, DjangoServer1 works.

Now, I want to run DjangoServer2 under same server: 12.12.12.12

Question: How to configure DjangoServer1 and DjangoServer2 to different port?

How to run gunicorn command to use different port? Following command uses port 8000? Why?

gunicorn --daemon --workers 3 --bind unix:/home/user/develop/DjangoServer1/DjangoServer1.sock DjangoServer1.wsgi

How to configure nginx file?

1
Can you try this gunicorn --daemon --workers 3 --bind :8080 DjangoServer1.wsgi?Dharanidhar Reddy
Thank you for reply. I stoped nginx, and did: gunicorn --daemon --workers 3 --bind :8080 loivideo.wsgi. localhost:8080 works. 12.12.12.12:8080 not work (should not work). Then, what should I do to /etc//etc/nginx/sites-available/DjangoServer1, so that mydomain1.com work? How to make mydomain2.com work?user3792705

1 Answers

1
votes

Change your Gunicorn command to run the servers on the specified port.

gunicorn --daemon --workers 3 --bind :8080 DjangoServer1.wsgi

Now change your NGINX conf file to forward it to the Application Server.

upstream django-server-1 {
    server 0.0.0.0:8080;
}


server {
    listen 0.0.0.0:80;
    server_name 127.0.0.1;

    location = /favicon.ico { access_log off; log_not_found off; }

    location /static/ {
            root /home/user/develop/DjangoServer1;
    }

    location / {
            include proxy_params;
            proxy_pass http://django-server-1;
            proxy_next_upstream off;
    }
}

Restart your NGINX service.

This will forward all the requests coming to 80 port to your application server DjangoServer1.

If you explicitly want to forward requests coming to 8080 to your application server, change the server block in the NGINX configuration or have a new server block with your rules.