您的位置:首页 > 运维架构 > 反向代理

关于Apache 设置反向代理的一个注意问题

2020-02-16 05:00 555 查看

     Apache 反向代理默认会改写Request head中的host,这样会造成在应用中如果使用reqeust.getHead("host")来做绝对路径的时候存在无法连接的问题。

    网上很多Apache的proxy设置都只写了ProxyPass 和 ProxyPassReverse

 ProxyPass /    http://172.18.100.51/
 ProxyPassReverse  /  http://172.18.100.51/
[/code]

    这个时候如果在应用中使用reqeust.getHead("host") 或者PHP中使用$_SERVER['HTTP_HOST'] 绝对路径来请求js或者css 就会是172.18.100.5,本地浏览器如果是在外网就无法访问了。

只需要在Apache中添加

ProxyPreserveHost On
[/code]

就可以解决这个问题

在Apache官方文档中关于他的描述

ProxyPreserveHost Directive
Description:Use incoming Host HTTP request header for proxy request
Syntax:ProxyPreserveHost On|Off
Default:ProxyPreserveHost Off
Context:server config, virtual host, directory
Status:Extension
Module:mod_proxy
Compatibility:Usable in directory context in 2.3.3 and later.
When enabled, this option will pass the Host: line from the incoming request to the proxied host, instead of the hostname specified in the ProxyPass line.
This option should normally be turned Off. It is mostly useful in special configurations like proxied mass name-based virtual hosting, where the original Host header needs to be evaluated bythe backend server.
[/code]

同理 Nginx 中也有一个类似的参数

proxy_set_header Host $host;
[/code]



转载于:https://my.oschina.net/caiw/blog/289103

  • 点赞
  • 收藏
  • 分享
  • 文章举报
chunyanhui9595 发布了0 篇原创文章 · 获赞 0 · 访问量 156 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: