4

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?

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

2
        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/;
                }
         }

The above should work. You are missing the '/' at the end of the proxy_pass url

Alternatively, you can do

         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;
                }
         }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.