I'm trying to deploy a Django app with Gunicorn and Nginx under a subpath, I'm inside a corporate network, and the path www.example.com/myapp points to the IP 192.168.192.77:8080 of my PC on the local network (I have no control over the pathing nor the corporate network, just that port exposed to the internet through /myapp). I tried many things including this: How to host a Django project in a subpath? , but it doesn't show the Django welcome page, just the Nginx welcome page. I also can't access to the Django admin page that should be on the path /myapp/admin, just a 404 page.
This is the config of my site on the folder sites-available for Nginx:
server {
listen 8080;
server_name 192.168.192.77;
location /myapp/static/ {
root /home/user/myapp;
}
location /myapp/ {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
I tried proxy_set_header SCRIPT_NAME /myapp; but it didn't work.
If I don't configure any paths, it shows the django welcome page at /myapp but then I can't acces /myapp/admin, also a 404.
Curiously, if I start the Django development server using python manage.py runserver without nginx it works, the django welcome page shows at /myapp and I can access /myapp/admin with the only problem that the CSS files don't load.
I already have FORCE_SCRIPT_NAME = '/myapp' and STATIC_URL = '/myapp/static'in settings.py for Django.
In conclusion, how do I deploy this Django app to a subpath?
www.example.com/myapp/myapp?www.example.com/myapp/myapp/. If I delete the last/it doesn't load at all, why?. On the other hand I need to delete one of the/myappin the sub path so it shows justwww.example.com/myapp/at the end. And built-in server can redirectmyapptomyapp/, but when you use external server then you have to do it on your own - probably using commandrewrite(like in regex - Add slash to the end of every url (need rewrite rule for nginx) - Stack Overflow)rewrite [^/]$ $uri/because this missing/can make problem with any URL which you have in Django - i.e./myapp/adminmyappthen you should remove onemyappfromdjango(ie.FORCE_SCRIPT_NAME = '/myapp') or fromlocation /myapp/. As for me you could userewriterather to convert/myappto/myapp/myapp- so when client will try to connect to/myappthen it will redirect it to current working/myapp/myapp