Nginx path with proxy pass

I have the following problem: I am trying to put a Django application with a gunicorn server on my VPS running Nginx. My nginx configuration is as follows:

upstream app_name { server unix:/path/to/socket/file.sock fail_timeout=10; } server { listen 80 default_server; listen[::]:80 default_server ipv6only=on; root /webapps/; server_name my_hostname.com; location / { proxy_set_header Host $http_host; } location /appname/ { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://app_name; } 

}

However, when I go to my_server.com/appname/ , I constantly get a 404 error. I'm still new to Nginx, could someone point me in the right direction, how to set the proxy password for the path /appname/ ? I should note that when the place for /appname/ replaced with / , the django application works fine.

+7
django proxy nginx gunicorn
source share
1 answer

You just need a forward slash for proxy_pass:

 proxy_pass http://app_name/; 

it will help you to carve out the "appname" prefix so that the configuration looks like this:

 upstream app_name { server unix:/path/to/socket/file.sock fail_timeout=10; } server { listen 80 default_server; listen[::]:80 default_server ipv6only=on; root /webapps/; server_name my_hostname.com; location /appname/ { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://app_name/; } 
+8
source share

All Articles