nginx前端apache后端 虚拟主机的配置

本文详细介绍了在CentOS系统中如何配置Nginx作为前端,Apache作为后端,实现虚拟主机的部署,包括设置多个端口监听、配置虚拟主机及使用Nginx作为负载均衡器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

centos系统中:nginx前端apache后端 虚拟主机的配置
apache httpd.conf中增加:
Listen 81
Listen 82
Listen 83
并同时开启:
Include conf/extra/httpd-vhosts.conf

httpd-vhosts.conf配置三个站点,分别对应81 82 83 三个端口,配置如下:

#-------------------- default root open with http://ip -------------------------
<VirtualHost *:81>
    ServerAdmin root@localhost
    DocumentRoot "/home/wwwroot/htdocs"
    ServerName 192.168.0.2
#    ServerAlias locahost 127.0.0.1
#    DirectoryIndex index.html index.html.var index.php
#   ErrorLog "logs/error.log"
#   CustomLog "logs/access.log" common
</VirtualHost>

#------------------------- virtual web www.aaa.com -----------------------------
<Directory /home/wwwroot/htdocs>
    AllowOverride ALL
    Allow from all
</Directory>

<VirtualHost *:82>
    ServerAdmin admin@gsywx.com
    DocumentRoot /home/wwwroot/htdocs/www.aaa.com
    ServerName www.aaa.com
#    ServerAlias *.aaa.com
#    ErrorLog "logs/www.aaa.com-error.log"
#    CustomLog "logs/www.aaa.com-access.log" common
</VirtualHost>

#------------------------- virtual web www.bbb.com -----------------------------
<Directory /home/wwwroot/htdocs>
    AllowOverride ALL
    Allow from all
</Directory>

<VirtualHost *:83>
    ServerAdmin admin@gsywx.com
    DocumentRoot /home/wwwroot/htdocs/www.bbb.com
    ServerName www.bbb.com
#    ServerAlias *.bbb.com
#    ErrorLog "logs/www.bbb.com-error.log"
#    CustomLog "logs/www.bbb.com-access.log" common
</VirtualHost>



nginx中的vhost.conf中配置对应的三个虚拟主机,配置如下:

  upstream  phppool1 {
  server 127.0.0.1:81;
   }

  upstream  phppool2 {
  server 127.0.0.1:82;
   }

  upstream  phppool3 {
  server 127.0.0.1:83;
   }

#------------------------------- default web dir -------------------------------
server
             {
                        listen 80;
                        server_name 192.168.0.2;
                        root /home/wwwroot/htdocs;
                        location / {
                              proxy_pass http://phppool1;
                              proxy_set_header Host $host;
}
}

#-------------------------------- www.aaa.com --------------------------------
server
             {
                        listen 80;
                        server_name www.aaa.com;
                        root /home/wwwroot/htdocs/www.aaa.com;
                        location / {
                              proxy_pass http://phppool2;
                              proxy_set_header Host $host;
}
}

#-------------------------------- www.bbb.com --------------------------------
server
             {
                        listen 80;
                        server_name www.bbb.com;
                        root /home/wwwroot/htdocs/www.bbb.com;
                        location / {
                              proxy_pass http://phppool3;
                              proxy_set_header Host $host;
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值