N
N
Nikodad2021-12-09 16:48:06
Django
Nikodad, 2021-12-09 16:48:06

How to deploy two django projects on the same server with nginx?

I have two versions of the same django project on the same server. One for sale, one for testing. The dev version differs in that its urls start with dev/. How can I configure nginx so that when one of the versions is accessed, nginx returns the statics of that version.

server {
    listen 80;
    server_name 1.1.1.1;
    access_log /var/log/nginx.access.log;
    error_log /var/log/nginx.error.log;

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    location /dev/ {
        proxy_pass http://127.0.0.1:8001;
        proxy_set_header Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Karabanov, 2021-12-09
@karabanov

Make two sections server.
In each, specify a separate one server_name, for example, test.example.com and prod.example.com.
In each, specify what you want, the settings you need for the application to work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question