[Django]-How to proxy proxy domain name to internal app server URL in Nginx?

3👍

Based on this answer here’s a configuration that seems to work as desired.

For app1 running on http://localhost:8000/app1_path :

upstream app1 {
    server 127.0.0.1:8000 fail_timeout=0;
}
server {
    listen 80;
    server_name example.com
    access_log /var/log/nginx/example.com.access.log;
    error_log /var/log/nginx/example.com.error.log;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        rewrite ^(.*)$ /app1_path$1 break;
        proxy_pass http://app1;
    }
}

So, one could repeat this pattern as many times as desired for each hostname->app/path pair.

Leave a comment