首頁  >  文章  >  後端開發  >  nginx 設定安裝教學課程

nginx 設定安裝教學課程

WBOY
WBOY原創
2016-08-08 09:25:23875瀏覽

nginx 設定安裝教學課程

Nginx ("engine x") 是高效能的 HTTP  反向代理 伺服器,也是一個 IMAP/POP3/SMTP 伺服器,也是一個 IMAP/POP3/SMTP 代理伺服器。  Nginx 是由 Igor Sysoev 為俄羅斯訪問量第二的 Rambler.ru 站點開發的,第一個公開版本0.1.0發佈於2004104日。其將原始程式碼以類別BSD許可證的形式發布,因其它的穩定性、豐富的功能集、範例設定檔和低系統資源的消耗而聞名。 201161日,

nginx 1.0.4

發布。

 


一般我們都需要先裝pcre, zlib,前者為了重寫rewrite,後者為了

gzip

壓縮。

1.

選定源碼目錄 選定目錄

 /usr/local/

 

cd /usr/local/

 

2.安裝

PCRE

cd /usr/local/

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

tar -zxvf pcre-8.21.tar.gz

cd pcre-8.21

./configure

make

make install

 

3.安裝

zlib

cd /usr/local/ 

wget http://zlib.net/zlib-1.2.8.tar.gz

tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8

./configure

make

make install

 

4.安裝

ssl

 

cd /usr/local/

wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz

tar -zxvf openssl-1.0.1c.tar.gz

./config

make

make install

 

5.安裝

nginx

 

Nginx 一般有兩個版本,分別是穩定版和開發版,您可以根據您的目的來選擇這兩個版本的其中一個,下面是把 Nginx 安裝到

 /usr/local/nginx 

目錄下的詳細步驟:

 

cd /usr/local/

wget http://nginx.org/download/nginx-1.2.8.tar.gz

tar -zxvf nginx-1.2.8.tar.gz

cd nginx-1.2.8  

./configure --prefix=

/usr/local/nginx 

make

make install

 

--with-pcre=/usr/src/pcre-8.21 指的是

pcre-8.21 

的源碼路徑。 --with-zlib=/usr/src/zlib-1.2.7 指的是

zlib-1.2.7 

的源碼路徑。

 

6.

啟動 確保系統的

 80 

連接埠未被其他程式佔用,

/usr/local/nginx/sbin/nginx

 

檢查是否啟動成功:

netstat -ano|grep 80 

有結果輸入說明啟動成功

 

 

開啟瀏覽器存取此機器的 IP,如果瀏覽器出現 Welcome to nginx! 則表示

 Nginx 

已經安裝成功運作。

 

7.

重啟

/usr/local/nginx/sbin/nginx –s reload

 

8.

修改設定檔

cd /usr/local/nginx/conf

vi nginx.conf

 

9.

常用nginx 配置

#nginx

運行使用者和群組

user    www www;  

#啟動進程,通常設定成和cpu

的數量相等

worker_processes  4;

 🎜 🎜

#全域錯誤日誌及PID檔案

pid /var/run/nginx.pid;

error_log  /var/log/nginx/error.log;

 

events {

        #epoll是多路復用IO(I/O Multiplexing)中的一種方式 , 可以大幅提升nginx的效能 use epoll;                    #

單一後台

worker process

進程的最大並發連結數

worker process進程的最大併發連結數         worker_connections  10240;

}

#

設定

http伺服器,利用它的反向代理功能提供負載平衡支援 http {

        include       mime.types;

 

        default_type  application/octet-stream;

 

         error_page 400 403 500 502 503 504  /50x.html;

 

        index index.html index.shtml

 

        autoindex off;

 

         fastcgi_intercept_errors on;

 

        sendfile        on;

 

        # These are good default values.

        tcp_nopush      on;

        tcp_nodelay     off;

 

        # output compression saves bandwidth

        gzip  off;

         #gzip_static on;

        #gzip_min_length  1k;

        gzip_http_version 1.0;

        gzip_comp_level 2;

        gzip_buffers  4 16k;

        gzip_proxied any;

        gzip_disable "MSIE [1-6].";

        gzip_types  text/plain text/html text/css application/x-javascript application/xml application/xml+rss text/javascript;

        #gzip_vary on;

 

        server_name_in_redirect off;

 

#

設定負載平衡的伺服器清單

        upstream portals {

                  server 172.16.68.134:8082 max_fails=2 fail_timeout=30s;

                  server 172.16.68.135:8082 max_fails=2 fail_timeout=30s;

                            server 172.16.68.136:80822 max0002 fail_m

                  server 172.16.68.137:8082 max_fails=2 fail_timeout=30s;

        }

 

        #upstream overflow {

         #       server 10.248.6.34:8090 max_fails=2 fail_timeout=30s    ;

         #       server 10.248.6.45:8080 max_fails=2 fail_timeout=30s    ;

        #}

 

        server {

                                   

                listen       8080;                 server_name  127.0.0.1;  

                   #403

404頁重新導向位址

                   error_page  403 = http://www.e100.cn/ebiz/other/217/403.html;

                   error_page  404 = http://www.e100.cn/ebiz/other/218/404.html;                    proxy_connect_timeout      90;

                   proxy_send_timeout         180;

                   proxy_read_timeout         180;

 

                   proxy_buffer_size 64k;

                   proxy_buffers 4 128k;

                   proxy_busy_buffers_size 128k;

 

 

                   client_header_buffer_size 16k;

                   large_client_header_buffers 4 64k;

 

                #proxy_send_timeout         3m;

                #proxy_read_timeout         3m;

                #proxy_buffer_size          4k;

                #proxy_buffers              4 32k;

 

                proxy_set_header Host $http_host;

                proxy_max_temp_file_size 0;

                #proxy_hide_header Set-Cookie;

                  

         #       if ($host != 'www.e100.cn') {

         #                重寫^/(.*)$ http://www.e100.cn/$1 永久;

         #       }

 

 

               位置/ {

                       以否定一切;

               }

 

                   位置 ~ ^/resource/res/img/blue/space.gif {

                    proxy_pass http://tecopera;

               }

 

               位置 = / {

                   在以中重寫 ^(.*)$  /ebiz/event/517.html;

               }

 

 

 

                   位置 = /ebiz/event/517.html {

                    add_header變更接受編碼;

                    root/data/web/html;

                    過期 10m;

               }

 

 

 

 

               位置 = /check.html {

                    root /usr/local/nginx/html/;

                    access_log 已關閉;

               }

 

               位置 = /50x.html {

                    root /usr/local/nginx/html/;

                    過期 1m;

                    access_log 已關閉;

               }

 

 

              location = /index.html {

                       add_header Vary Accept-Encoding;

#定義伺服器的預設網站根目錄位置

                    root/data/web/html/ebiz;

                    expires 10m;

               }

#定義反向代理存取名稱

                   location ~ ^/ecps-portal/* {

                   # expires 10m;

#重定向叢集名稱

                    proxy_pass http://portals;

                    #proxy_pass http://172.16.68.134:8082;

               }

 

                   location ~ ^/fetionLogin/* {

                   # expires 10m;

                    proxy_pass http://portals;

                    #proxy_pass http://172.16.68.134:8082;

                }

 

                   #location  ~ ^/business/**                                     

                #                                                 

                #    proxy_pass http://172.16.68.132:8088;                                       

                #    #proxy_pass http://172.16.68.134:8082                                    

                #}

 

                   location ~ ^/rsmanager/* {

                    expires 10m;

                    root/data/web/;

                    #proxy_pass http://rsm;

               }

#定義nginx處理的頁面後綴

                   location ~* (.*).(jpg|gif|htm|html|png|js {

                            root/data/web/html/;

#頁面快取時間為10分鐘

                         expires 10m;

                   }

 

#設定查看Nginx狀態的位址     

               location ~* ^/NginxStatus/ {

                    stub_status on;

                    access_log off;

                    allow 10.1.252.126;

                    allow 10.248.6.49;

                    allow 127.0.0.1;

                    deny all;

               }

         #       error_page   405 =200 @405;

         #       location @405

         #       {

         #                proxy_pass http://10.248.6.45:8080;

         #       }  

 

               access_log  /data/logs/nginx/access.log combined;

               error_log   /data/logs/nginx/error.log;

        }

         server {

                listen       8082;

 

                server_name  _;

               位置 = /check.html {

                    root /usr/local/nginx/html/;

                    access_log 已關閉;

               }

                  

        }

         伺服器 {

                   聽       8088;

                   server_name  _;

                   位置 ~ ^/* {

                   root/data/web/b2bhtml/;

                   access_log 結束;

         }                

         }

        伺服器 {

                聽       9082;

                server_name  _;

 

        #        位置 ~ ^/resource/* {

        #            已使用 10m;

         #           root/data/web/html/;

         #       }

 

                位置  / {

                     root/data/web/html/sysMaintain/;

                       if (!-f $request_filename) {

                            以重寫 ^/(.*)$/sysMaintain.html 最後;

                          }

                }

        }

 

}


以上就介紹了nginx設定安裝教學課程,包含了nginx設定的內容,希望對PHP教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn