Question

I want to setup two different Django projects in my VPS - there are two different Gunicorn instances (two different virutalenvs). The first project works perfectly:

Nginx for first project:

server {
server_name 95.85.34.87;

access_log off;
    sendfile off;

location /static/ {
    root Lynx/lynx/lynx_static_files/;
}

location / {
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Methods "GET,POST,OPTIONS";
    add_header         Access-Control-Allow-Headers   Content-Type;
    add_header         Access-Control-Max-Age         86400;
    proxy_pass http://127.0.0.1:8001;
    proxy_set_header X-Forwarded-Host $server_name;
    proxy_set_header X-Real-IP $remote_addr;
    add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
}
}

Gunicorn for first project:

gunicorn_django --bind localhost:8001

Nginx for second project:

server {
server_name 95.85.34.87:8002;

access_log off;
    sendfile off;

location /static/ {
    root Komodo/komodo/komodo_static_files/;
}

location / {
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Methods "GET,POST,OPTIONS";
    add_header         Access-Control-Allow-Headers   Content-Type;
    add_header         Access-Control-Max-Age         86400;
    proxy_pass http://127.0.0.1:8002;
    proxy_set_header X-Forwarded-Host $server_name;
    proxy_set_header X-Real-IP $remote_addr;
    add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
}
}

Gunicorn for second project:

gunicorn_django --bind 95.85.34.87:8002

Problem: 95.85.34.87 shows my first project with static files (everything works fine), 95.85.34.87:8002 also works (Gunicorn is working), but unfortunately Nginx doesn't serve static files for this second project for some reason. I think the reason behind the problem is server_name setting, but i am not sure how to set it up to show my statics for second project.

Was it helpful?

Solution

I have fixed my problem. I have just binded my second Project's Gunicicorn instance not to 95.85.34.87, but to localhost:8002 (same as project 1, but different port).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top