nginx - django redirect to relative path
黄舟
黄舟 2017-05-16 17:24:35
0
1
704

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.

But the redirection inside Django doesn’t know how to pass the real URI and path, or it can use relative paths instead of absolute paths when redirecting inside Django.

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
洪涛

https://docs.djangoproject.com/en/dev/ref/settings/#use-x-forwarded-ho...

https://docs.djangoproject.com/en/1.8/ref/settings/#force-script-name

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!