Nginx如何重写proxy_set_header主机

时间:2018-07-16 10:22:35

标签: nginx url-rewriting reverse-proxy proxypass

我有一个CNAME admin.testdomain.com,为此我使用nginx指向在另一个nginx服务器后面工作的django应用程序。该应用程序具有仅允许admin.testdomain.com域会话的中间件。现在,我有一个CNAME user.testdomain.com,它指向同一应用程序。如果要建立会话,则需要在nginx虚拟主机条目中为proxy_set_header Host "admin.testdomain.com";设置usr.testdomain.com。补充说是可行的,但是一旦建立会话,URL就会自动从admin.testdomain.com重写为user.testdomain.com.。下面是我的配置。

为user.testdomain.com配置:

server {
  server_name user.testdomain.com;

. . .

location /admin/search {
limit_req zone=testsearch;
proxy_pass http://testpass;
proxy_set_header Host "admin.testdomain.com"; # without this, the session won't be allowed by the middleware, but this redirects user.testdomain.com to admin.testdomain.com
}

我尝试设置

proxy_redirect https://admin.testdomain.com https://user.testdomain.com ; 在同一块中没有任何作用,甚至是重写规则也会导致太多重定向错误。有没有解决方法可以解决这个问题?

谢谢。

0 个答案:

没有答案
相关问题