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

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

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

 ProxyPass /    http://172.18.100.51/
 ProxyPassReverse  /  http://172.18.100.51/

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

只需要在Apache中添加

ProxyPreserveHost On

就可以解决这个问题

在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.

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

proxy_set_header Host $host;



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

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值