Hosting a django project behind proxypass

蹲街弑〆低调 提交于 2019-12-11 01:24:29

问题


I have hosted to django admin project on a local machine X. http://10.4.x.y/myapp/admin works. I have an external IP on another machine Y and i am doing a proxy pass from the Y to X.

http://proxypassname.com/myapp/admin works. But, When i click the link "Save" or "Save continue editing" button after editing in admin page, it redirects to local machine ip (i.e. http://10.4.x.y/myapp/blah_blah_blah).

How to make sure that the django project redirects to proxypass name instead of local IP?


回答1:


This is happening because the admin redirects to IP it thinks it has. It gets in in the HTTP request's header.

However, the fix is very easy. Assuming you proxy server implements the X-Forwarded-For standard, it could be easily fixed.

in your settings.py, simply set:

USE_X_FORWARDED_HOST = True

and restart your Django.

If that doesn't work, you can try to see if your proxy sets a different kind of header, and write a middleware that does the same thing. It's the first example on Django's documentation chapter on middleware




回答2:


I did these two things and it worked.

  1. Whenever you add a ProxyPass, you should add ProxyPassReverse

  2. SITE_ID should be set to the domain where you want to point this django project.



来源:https://stackoverflow.com/questions/14813314/hosting-a-django-project-behind-proxypass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!