1. 程式人生 > >nginx做負載+apache多虛擬web主機的部署1專業做法

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