標籤:
以CentOS 7為例,我們類比實現nginx來處理靜態資源,apache來處理php
1.首先我們來安裝nginx
# wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2.建立YUM倉庫
# rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
3.安裝nginx
yum install nginx
4.啟動nginx並設定為開機啟動
nginx 啟動nginx 如果機器上面已經安裝了apache此次會報錯。我們需要修改連接埠
systemctl enable nginx 開機啟動
5.修改nginx的設定檔,設定一個新連接埠
cd /etc/nginx --進入nginx目錄
vi nginx.conf --修改配置
# include /etc/nginx/conf.d/*.conf; 注釋掉此行,為了避免載入conf.d目錄下的配置 server { listen 88 ; 重新設定連接埠 # server_name test.com;
location /{ root /usr/share/nginx/html; 預設目錄 index index.html index.htm; } location ~ \.php$ { PHP路由轉向規則 proxy_pass http://192.168.0.101:80; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { PHP處理檔案及目錄(本機apache) root /var/www/html; fastcgi_pass 192.168.0.101:80; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; }
這樣html資源就留在了localhost:88,php資源就轉向192.168.0.101
CentOS 7虛擬機器下類比實現nginx負載平衡