X
X
Xmahopnya2021-12-16 14:39:33
Django
Xmahopnya, 2021-12-16 14:39:33

How to deploy django project to nginx subpath?

There is a project on django built in a docker container, together with nginx it is assembled in docker-compose, on the IP address to which the port is forwarded.
It looks like this ipaddress : 84 in this case everything works fine .
the host machine and holds the main site, for example example.com/my_app
But if you do a regular proxy_pass in the host nginx, then all the application urls go astray, and you need to hardcode the 'my_app' prefix in them, but I would like to avoid this

Here are the configs:
Nginx on the host

server {
  server_name example.com;

  location /my_app{
        proxy_pass http://ip_address:84;
  }
}


Nginx that runs in a container and proxies to the application container
upstream db {
    server app:8000;
}
server {
    listen 80;
    server_name ip_address;
    location / {
        proxy_pass http://app:8000;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
    }
}


I don't know how best to proceed. Maybe completely remove the container nginx?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
ky0, 2021-12-16
@ky0

Read about the trailing slash in the proxy_pass.

A
Alexander Karabanov, 2021-12-16
@karabanov

server {
  server_name example.com;

  location ^~ /my_app/ {
        proxy_pass http://ip_address:84/;
  }
}

proxy_pass

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question