linux下的nginx功能及安裝

來源:互聯網
上載者:User

標籤:style   http   tar   color   get   strong   

1. nginx 作為反向 Proxy的優異性,具備不可替代的作用:

  1. HTTP層的交換,可以用來分流使用者,比如根據使用者的ID是偶數還是奇數來分流
  2. 負載平衡
  3. 用於緩衝Server
  4. URL rewrite:URL重寫
  5. 安裝第三方外掛程式,實現健康狀態監測

Nginx可以同時響應上萬的請求,效率要高於Apache Server。

 

2. Nginx配置中實現負載平衡公司使用兩種方式:

  • 根據weight:location -> proxy_pass -> upstream -> 在upstream中不同的後端Server配置不同的weight
  • 根據Hash: location -> proxy_pass -> upstream -> 在upstream將網域名稱之後的位置請求Hash後分配到不同的後端Server

3.安裝

在安裝nginx之前,必須安裝pcre,以支援重寫,正則以及網頁壓縮等等。所以需要安裝perl大量的支援模組,這些模組被封裝成為一個pcre,可以使用yum install 來安裝,也可以去官網下載最新版的prce包。

下載包的安裝過程如下:

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.gz

 解壓

cd 該目錄

執行./configure --enable-utf8

執行檢查 make check

執行安裝程式 make  && make install

 

接下來安裝nginx,步驟和上面基本差不多: wget http://nginx.org/download/nginx-1.7.1.tar.gz

 解壓

cd 該目錄

執行 ./configure --prefix=/usr/local/nginx --with-http_stub_status_module

執行安裝:make install

 

安裝完成之後,驗證一下:

 cat /usr/local/nginx/conf/nginx.conf

 cd  /usr/local/nginx/sbin

 ./nginx -t

出現:

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

啟動

./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.