nginx做负载+apache多虚拟web主机的部署1专业做法
192.168.3.3 apache1 192.168.3.4 apache2

vim /etc/httpd/conf.d/www.conf
namevirtualhost *:80
<VirtualHost *:80>
    DocumentRoot /var/www/html/wwwhao315com
    ServerName www.hao315.com
    ServerAlias www.315002.com
    <Directory "/var/www/html/wwwhao315com">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>
<VirtualHost *:80>      
    DocumentRoot /var/www/html/3ghao315com
    ServerName 3g.hao315.com
    ServerAlias 3g.315002.com
    <Directory "/var/www/html/3ghao315com">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>
<VirtualHost *:80>

这一段的意思是开启目录的rewrite模式

<Directory "/var/www/html/3ghao315com">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
 </Directory

由于www.wkphp.com和www.wkhttp.com的目录属于一个,开启rewrite权限一样,所以可以共用一个<VirtualHost *:80>并可以添加另外相同的web目录的其他域名
ServerAlias www.315002.com www.abc.com 多域名之间用空格隔开
192.168.3.7 nginx的配置
vim /usr/local/nginx/conf/nginx.conf http模块中添加

upstream www.hao315.com {
        server 192.168.3.3:80 weight=1;
        server 192.168.3.4:80 weight=1;
    }
    server {
        listen 80;
        server_name www.hao315.com www.315002.com 3g.hao315.com 3g.315002.com admin.99hao315.com;
        location / {
            proxy_pass http://www.hao315.com/;
            index index.html index.htm index.php;
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }     

重点1 多域名的servername ,中间用空格隔开

server_name www.hao315.com www.315002.com 3g.hao315.com 3g.315002.com admin.99hao315.com;

重点2 host header

                proxy_redirect off;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for

相关文章:

  • 2021-07-03
  • 2021-06-22
  • 2022-01-10
  • 2021-11-17
  • 2022-02-24
猜你喜欢
  • 2021-12-19
  • 2021-12-03
  • 2021-06-12
  • 2022-02-08
  • 2022-02-09
  • 2021-11-13
  • 2021-06-10
相关资源
相似解决方案