CentOS 7虛擬機器下類比實現nginx負載平衡

來源:互聯網
上載者:User

標籤:

以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負載平衡

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.