cherrypy.HTTPRedirect使用ABS路径重定向到IP而不是主机名 [英] cherrypy.HTTPRedirect redirects to IP instead of hostname using abs path

查看:117
本文介绍了cherrypy.HTTPRedirect使用ABS路径重定向到IP而不是主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在nginx后面运行CherryPy,需要处理重定向.在运行127.0.0.1:8080的开发人员机器上,这可以正确重定向到127.0.0.1:8080/login.

I'm running CherryPy behind nginx and need to handle redirects. On my dev machine running on 127.0.0.1:8080, this redirects correctly to 127.0.0.1:8080/login.

但是,当在cherrypy.mydomain.com(端口80)上通过nginx运行时,重定向仍将转到127.0.0.1:8080/login,而不是cherrypy.mydomain.com/login. 127.0.0.1:8080是应用程序的正确本地地址,但是nginx中的应用程序服务器设置为侦听端口80,并将请求通过管道传递到127.0.0.1:8080上的本地Cherrypy服务器,但不应直接公开此地址.

However when running via nginx on cherrypy.mydomain.com (port 80), the redirects are still going to 127.0.0.1:8080/login rather than cherrypy.mydomain.com/login. 127.0.0.1:8080 is the correct local address for the application, however the application server in nginx is set to listen on port 80 and pipe requests to the local cherrypy server on 127.0.0.1:8080, but shouldn't directly expose this.

我的应用中的相关行是:

The relevant lines in my app are:

身份验证失败:

raise cherrypy.HTTPRedirect("/login")

并在我的控制器中:

cherrypy.config.update({
    'tools.encode.on': True, 'tools.encode.encoding': 'utf-8',
    'tools.decode.on': True,
    'tools.trailing_slash.on': True,
    'server.socket_host' : '127.0.0.1',
    'server.socket_port' : 8080,
})

我想知道除了套接字主机之外,服务器/主机名是否还有其他cherrypy配置项,但是我正在努力在文档中找到它.

I was wondering if there was an additional cherrypy config item for the server/host name in addition to the socket host, but I'm struggling to find it in the Docs.

本质上,我所需要做的只是让Cherrypy重定向到cherrypy.mydomain.com主机名,而不是内部IP.

Essentially, all I need is for cherrypy to redirect to the cherrypy.mydomain.com hostname rather than the internal IP.

谢谢!

推荐答案

尝试另外,您可能需要

'tools.proxy.local': 'X-Forwarded-Host',

设置为适当的标题.使用 NGINX 时,标题为

Set to appropriate header. When using NGINX, the header would be

'tools.proxy.local': 'Host',

对于 Lighttpd ,此标头将是合适的:

In case of Lighttpd this header will be appropriate:

'tools.proxy.local': 'X-Host'

这篇关于cherrypy.HTTPRedirect使用ABS路径重定向到IP而不是主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆