免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2568 | 回复: 2
打印 上一主题 下一主题

前nginx,后Apache多域名的访问? [复制链接]

论坛徽章:
1
数据库技术版块每日发帖之星
日期:2015-10-11 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-07-18 15:05 |只看该作者 |倒序浏览
请教一下,我前端用nginx反向代理,后端用Apache来负载,但是当客户端访问时,始终访问的是apache的第一个虚拟主机,请问怎么解决?
Nginx配置:
  1. upstream bakend {
  2.         server 192.168.8.221 weight=10; # max_fails=2 fail_timeout=2;
  3. }
  4. upstream bakend2 {
  5.         server 192.168.8.221 weight=10; # max_fails=2 fail_timeout=2;
  6. }
  7. server{
  8.        listen   80 default;
  9.        server_name      _;
  10.         return 403;
  11.      }
  12. server {
  13.     listen       80;
  14.     server_name  bbs.test.com;
  15.     location / {
  16.         proxy_pass http://bakend/;
  17.         proxy_set_header X-Real-IP "$remote_addr from $host";
  18.     }
  19.     error_page   500 502 503 504  /50x.html;
  20.     location = /50x.html {
  21.         root   /usr/share/nginx/html;
  22.     }
  23. }
  24. server {
  25.         listen         80;
  26.         server_name www.test.com;
  27.        
  28.         location / {
  29.         proxy_pass http://bakend2/;
  30.         proxy_set_header X-Real-IP "$remote_addr from $host";
  31.         }
  32.     error_page   500 502 503 504  /50x.html;
  33.             location = /50x.html {
  34.                 root   /usr/share/nginx/html;
  35.         }       
  36. }
复制代码
Apache虚拟主机配置:
NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot /www/html
    ServerName www.test.com
    ErrorLog logs/www.test.com-error_log
    CustomLog logs/www.test.com-access_log common
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot /www/bbs
    ServerName bbs.test.com
    ErrorLog logs/bbs.test.com-error_log
    CustomLog logs/bbs.test.com-access_log common
</VirtualHost>
主页内容为:
# cat /www/html/index.html
<h1>Welcome to First Apache Page!<h1/>
# cat /www/bbs/index.html
<h1>Welcome to First Apache-BBS Page!<h1/>

客户端访问时http://www.test.com和bbs.test.com的内容都是Welcome to First Apache Page!
Apache用基于域名的虚拟主机这个问题要怎么解决?请高手指点!

论坛徽章:
9
巳蛇
日期:2013-12-05 15:03:33戌狗
日期:2013-12-10 20:52:35白羊座
日期:2014-12-30 14:11:58处女座
日期:2015-01-15 14:33:442015年亚洲杯纪念徽章
日期:2015-01-28 13:37:36羊年新春福章
日期:2015-01-30 15:03:352015年亚洲杯之约旦
日期:2015-02-09 17:07:552015年亚洲杯之韩国
日期:2015-03-26 15:04:132015年亚洲杯之卡塔尔
日期:2015-04-04 16:35:54
2 [报告]
发表于 2014-07-21 10:56 |只看该作者
apache 上换个端口即可!

论坛徽章:
0
3 [报告]
发表于 2014-07-29 11:02 |只看该作者
不要用地址,用域名!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP