The deployment environment is Nginx gunicorn Django
Nginx configuration is as follows
location /app1 {
rewrite ^/app1/(.*)$ / break;
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_redirect off;
proxy_pass http://11.11.11.1:8001;
}
location /app2 {
rewrite ^/app2/(.*)$ / break;
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_redirect off;
proxy_pass http://11.11.11.1:8002;
}
app1 and app2 are different applications. The following are the problems encountered
When accessing /app1/test
, Django will add slash at the end and redirect. The problem is that it will redirect /test/
instead of / app1/test/
When accessing /app1/admin
, it will be redirected to /admin/login/?next=/admin/
.
In my own program, for example, when Oauth authentication requires a redirection URI, I think of passing $http_host/app1
through X-host## when using Nginx proxy. # Passed to the backend Django, and then get the real URI.
https://docs.djangoproject.com/en/dev/ref/settings/#use-x-forwarded-ho...
https://docs.djangoproject.com/en/1.8/ref/settings/#force-script-name