apache的proxy代理总访问后端web的第一个虚拟主机

回复 收藏
问题,如题。怎么折腾都是一直访问第一个虚拟主机,后来找到问题所在。是我配置的不对。错误配置是这样的:
  1.     ServerName www.test.com
  2.     CustomLog "/dev/null" combined
  3.    ProxyRequests Off
  4.         
  5.         Order deny,allow
  6.         Allow from all
  7.         
  8.     ProxyPass / http://192.168.13.111/
  9.      ProxyPassReverse / 192.168.13.111/
问题出在了:  ProxyPass / http://192.168.13.111/
要改成这样:  ProxyPass / http://www.test.com/

所以正确的配置是这样的:
  1.     ServerName www.test.com
  2.     CustomLog "/dev/null" combined
  3.    ProxyRequests Off
  4.         
  5.         Order deny,allow
  6.         Allow from all
  7.         
  8.     ProxyPass / http://www.test.com/
  9.      ProxyPassReverse / 192.168.13.111/

另外需要注意的是,需要在/etc/hosts 中加一条记录  
192.168.13.111  www.test.com
2011-12-21 17:39 举报
已邀请:
0

lyhabc

赞同来自:

居然不能写ip
0

杭州小白

赞同来自:

proxy是反向代理的功能?
0

starry

赞同来自:

本帖最后由 starry 于 2016-2-1 17:30 编辑

我按您的方法时
  1. <VirtualHost *:80>
  2.     ServerAdmin webmaster@dummy-host.example.com
  3.     DocumentRoot "/usr/local/apache2/htdocs/"
  4.     ServerName dummy-host.example.com
  5.     ServerAlias www.dummy-host.example.com
  6. </VirtualHost>

  7. <VirtualHost *>
  8.     ServerName www.discuz.com
  9.     CustomLog "/dev/null" combined
  10.     ProxyRequests Off

  11.     <Proxy *>
  12.         Order deny,allow
  13.         Allow from all
  14.     </Proxy>

  15.     ProxyPass / http://www.discuz.com/
  16.     ProxyPassReverse / 192.168.0.105/
  17. </VirtualHost>
出现如下警告
# apachectl -t
[Mon Feb 01 17:15:38 2016] [warn] NameVirtualHost *:80 has no VirtualHosts
Syntax OK
# apachectl graceful
[Mon Feb 01 17:16:12 2016] [warn] NameVirtualHost *:80 has no VirtualHosts

访问的web是proxy服务器上的默认虚拟主机
查看错误日志
  1. [Mon Feb 01 17:27:33 2016] [notice] Graceful restart requested, doing restart
  2. [Mon Feb 01 17:27:33 2016] [warn] NameVirtualHost *:80 has no VirtualHosts
  3. [Mon Feb 01 17:27:33 2016] [notice] Apache/2.2.24 (Unix) PHP/5.4.44 configured -- resuming normal operations
  4. [Mon Feb 01 17:27:33 2016] [error] proxy: ap_get_scoreboard_lb(1) failed in child 7094 for worker proxy:reverse
  5. [Mon Feb 01 17:27:33 2016] [error] proxy: ap_get_scoreboard_lb(0) failed in child 7094 for worker http://www.discuz.com/
  6. [Mon Feb 01 17:27:33 2016] [error] proxy: ap_get_scoreboard_lb(1) failed in child 7093 for worker proxy:reverse
  7. [Mon Feb 01 17:27:33 2016] [error] proxy: ap_get_scoreboard_lb(0) failed in child 7093 for worker http://www.discuz.com/
  8. [Mon Feb 01 17:27:33 2016] [error] proxy: ap_get_scoreboard_lb(1) failed in child 7095 for worker proxy:reverse
  9. [Mon Feb 01 17:27:33 2016] [error] proxy: ap_get_scoreboard_lb(0) failed in child 7095 for worker http://www.discuz.com/
  10. [Mon Feb 01 17:27:33 2016] [error] proxy: ap_get_scoreboard_lb(1) failed in child 7092 for worker proxy:reverse
  11. [Mon Feb 01 17:27:33 2016] [error] proxy: ap_get_scoreboard_lb(0) failed in child 7092 for worker http://www.discuz.com/
  12. [Mon Feb 01 17:27:33 2016] [error] proxy: ap_get_scoreboard_lb(1) failed in child 7091 for worker proxy:reverse
  13. [Mon Feb 01 17:27:33 2016] [error] proxy: ap_get_scoreboard_lb(0) failed in child 7091 for worker http://www.discuz.com/
  14. [Mon Feb 01 17:27:35 2016] [error] proxy: ap_get_scoreboard_lb(1) failed in child 7096 for worker proxy:reverse
  15. [Mon Feb 01 17:27:35 2016] [error] proxy: ap_get_scoreboard_lb(0) failed in child 7096 for worker http://www.discuz.com/





改为时,没有报错
# apachectl -t
Syntax OK
# apachectl restart

但是访问结果是500
Internal Server ErrorThe server encountered an internal error ormisconfiguration and was unable to completeyour request.
Please contact the server administrator, you@example.com and inform them of the time the error occurred,and anything you might have done that may havecaused the error.
More information about this error may be availablein the server error log.

查看错误日志
[warn] proxy: No protocol handler was valid for the URL /. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.

查看httpd.conf文件,已经加载了该模块
LoadModule proxy_module       modules/mod_proxy.so






0

starry

赞同来自:

starry 发表于 2016-2-1 17:24
我按您的方法时
出现如下警告
# apachectl -t

{:7_193:}
问题解决了,一开始我只安装了 mod_proxy.c prox_util.c 这两个模块,后来查了下 是下面几个也都要装,然后用的是

#/usr/local/apache2/bin/apxs -i -c -a mod_proxy.c prox_util.c
#/usr/local/apache2/bin/apxs -i -c -a mod_proxy_http.c
#/usr/local/apache2/bin/apxs -i -c -a mod_proxy_connect.c
0

善思致用

赞同来自:

starry 发表于 2016-2-1 17:43
问题解决了,一开始我只安装了 mod_proxy.c prox_util.c 这两个模块,后来查了下 是下面几个 ...

你在前面定义一个NameVirtualHost * 然后用应该也是可以的吧
0

善思致用

赞同来自:

starry 发表于 2016-2-1 17:43
问题解决了,一开始我只安装了 mod_proxy.c prox_util.c 这两个模块,后来查了下 是下面几个 ...

问一下,如果源文件里没有mod_proxy.c prox_util.c  mod_proxy_http.c   mod_proxy_connect.c这几个c文件,是不是只能重新编译了?
0

wanmei

赞同来自:

了解
0

riverxyz

赞同来自:

ProxyRequests Off 这的意思不是关闭代理吗?
0

hegeng

赞同来自:

学习
0

jackwolf

赞同来自:

老师,这个没看懂,问题“代理总访问后端web的第一个虚拟主机”,这个问题问的是什么意思?
0

jackwolf

赞同来自:

ProxyPass / http://www.test.com/
0

jackwolf

赞同来自:

老师,没看懂,问题中的‘总访问后端web的第一个虚拟主机’是什么意思?
代码中的ProxyPass / http://www.test.com/

     ProxyPassReverse / 192.168.13.111/在原系统中都代表什么?
0

llill

赞同来自:

学习。

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: