0

I have a Python/Django API with a unique endpoint /videos running on my Debian server.

The Nginx vhost looks like this:

server {

    server_name example.com;

    location / {
        # Pass to Uvicorn/Gunicorn web server service
        proxy_pass http://upstream_name/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /path_to/fullchain.pem; # managed by Certbot
    ssl_certificate_key /path_to/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

upstream upstream_name {
    server 127.0.0.1:8002;
}

Thus, it successfully serve the app and its unique endpoint on https://example.com/videos.

Now, I would like to serve the app on https://example.com/my_app/videos, in order to have in the future a other apps served on the same domain/vhost (with different internal ports, different upstreams in the vhost of course).

I've been reading several similar Q/A on ServerFault, and have been trying changing location / to location /my_app, while trying different trailing slashes configs on location and proxy_pass, with no success. What am I missing here?

EDIT: More precisely:

  • With the vhost changed to location /myapp -> https://example.com/my_app/videos displays a Not Found error (not from Nginx)

  • With the vhost changed to location /my_app/ -> https://example.com/my_app/videos get redirected to https://example.com/videos/ and displays a 404 Not Found error (from Nginx)

bolino
  • 273
  • 3
  • 15
  • 1
    Please show the exact configuration you tried, and what steps you took to reproduce the issue? – Tero Kilkanen Aug 06 '21 at 21:09
  • @TeroKilkanen Sure, edited. – bolino Aug 08 '21 at 03:55
  • 1
    You need to configure the new root URL in your application. To me, the second failure looks like your application sends the redirect to `/videos` URI. – Tero Kilkanen Aug 08 '21 at 10:22
  • You're right, it needs a config on app's side. I solved it by adding FORCE_SCRIPT_NAME param on Django's setting. More precisely, it needs FORCE_SCRIPT_NAME = '/my_app/' WITH the trailing slash. – bolino Aug 08 '21 at 12:17

0 Answers0