Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up Django with nginx reverse proxy

Tags:

nginx

django

I have a Django project that I have up and running with the development server at 127.0.0.1:8888. I'm trying to get it to run on my vps with nginx, so I can see it at example.com/djangoApp.

Here's my nginx.conf:

server {
    server_name example.com;
            location /otherLocation/ {
                    proxy_pass http://127.0.0.1:10000;
            }

            location /djangoApp/ {
                     proxy_pass http://127.0.0.1:8888;
            }

When I navigate to example.com/djangoApp, it throws an error: "Using the URLconf defined in djangoApp.urls, Django tried these URL patterns, in this order: /admin The current path, djangoApp/, didn't match any of these."

Can I modify the root url in settings.py to mitigate this?

like image 653
BenJ Avatar asked Sep 17 '25 03:09

BenJ


1 Answers

I fixed this by adding to nginx.conf:

location /djangoApp {
    rewrite  ^/djangoApp/(.*) /$1 break;
    proxy_pass http://127.0.0.1:8888;
}

Thanks to this SO exchange.

like image 65
BenJ Avatar answered Sep 18 '25 17:09

BenJ