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/wk
    ServerName www.wkphp.com
    ServerAlias www.wkhttp.com
    <Directory "/var/www/html/wk">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>
<VirtualHost *:80>      
    DocumentRoot /var/www/html/123
    ServerName www.123php.com
    ServerAlias www.123http.com
    <Directory "/var/www/html/123">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>
<VirtualHost *:80>

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

<Directory "/var/www/html/wk">
        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.wkphp.com {
        server 192.168.3.3:80 weight=1;
        server 192.168.3.4:80 weight=1;
    }
    server {
        listen 80;
        server_name www.wkphp.com www.wkhttp.com www.123php.com www.123http.com;
        location / {
            proxy_pass http://www.wkphp.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.wkphp.com www.wkhttp.com www.123php.com www.123http.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

猜你喜欢

转载自blog.csdn.net/weixin_43945743/article/details/85253342