国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Nginx之開門見山

Nginx之開門見山


目錄:
一、簡介
二、安裝
三、服務(wù)控制
四、配置文件說明
五、應(yīng)用實(shí)例

一、簡介
    Nginx是一款開放源代碼的高性能HTTP服務(wù)器、反向代理服務(wù)器,同時(shí)支持IMAP/POP3代理服務(wù),這是一款自由的軟件。
    Igor Ysyoev在2002年開始開發(fā)該軟件,于2004年發(fā)布第一個公開版本。
    Nginx以高性能、高可用、豐富的功能模塊、簡單明了的配置文檔以及低資源占用而著稱。Nginx采用最新的網(wǎng)絡(luò)I/O模型,支持高達(dá)50 000個并發(fā)連接。
    近年來Nginx在國內(nèi)取得了突飛猛進(jìn)的發(fā)展,很多門戶網(wǎng)站開始提供Nginx解決方案。
   
二、安裝
    Nginx軟件可以到官網(wǎng)下載:http://nginx.org/en/download.html,目前最新的穩(wěn)定版為1.2.2。本文運(yùn)行環(huán)境為Nginx-1.2.2,CentOS6.2。
    1. 二進(jìn)制包安裝:
    (nginx for CentOS/Red Hat):
        [root@centos6 ~]# cat > /etc/yum.repos.d/nginx.repo <<EOF

  1. >[nginx] 
  2. >name=nginx rpm 
  3. >baseurl=http://nginx.org/packages/centos/6/x86_64/ 
  4. >gpgcheck=0 
  5. >enabled=1 
  6. >EOF 

        [root@centos6 ~]# yum clean all
        [root@centos6 ~]# yum install nginx-1.2.2

  注意:http://nginx.org/packages/centos/6/x86_64/,路徑需要根據(jù)你自己的實(shí)際系統(tǒng)版本與架構(gòu)填寫。

    (nginx for Debain/Ubuntu):
        jacob@ubuntu ~$ sudo cat >> /etc/apt/sources.list <<EOF

  1. >deb http://nginx.org/packages/ubuntu/ lucid nginx 
  2. >deb-src http://nginx.org/packages/ubuntu/ lucid nginx 
  3. >EOF 


        jacob@ubuntu ~$ sudo atp-get update
        jacob@ubuntu ~$ sudo apt-get install nginx
    2. 源碼安裝:
        [root@centos6 ~]# wget http://nginx.org/download/nginx-1.2.2.tar.gz
        [root@centos6 ~]# tar -xzf nginx-1.2.2.tar.gz  -C  /usr/src
        [root@centos6 ~]# cd /usr/src/nginx-1.2.2
        [root@centos6 ~]# ./configure    --prefix=/usr/local/nginx \
        > --with-ipv6                        \
        > --with-http_ssl_module            \
        > --with-http_realip_module            \
        > --with-http_addition_module        \
        > --with-http_image_filter_module    \
        > --with-http_dav_module            \
        > --with-http_flv_module            \
        > --with-http_mp4_module            \
        > --with-http_gzip_static_module    \
        > --with-http_perl_module            \
        > --with-mail                        \
        > --with-mail_ssl_module

    注意:

configure執(zhí)行時(shí)會依賴與一些其他程序,如會出現(xiàn)報(bào)錯信息(./configure: error: C compiler gcc is not found)可根據(jù)提示安裝相應(yīng)的軟件包即可。
常見的軟件包有(gcc,pcre,pcre-devel,openssl,openssl-devel,gd,gd-devel,perl- 5.10.1-127,perl-ExtUtils),其中g(shù)d-devel在CentOS6.2光盤中沒有,需要從互聯(lián)網(wǎng)安裝。
configure的選項(xiàng)可以根據(jù)的自己需求輸入,最簡單的就是./configure不添加任何選項(xiàng),所有設(shè)置均為默認(rèn)。

        [root@centos6 ~]# make
        [root@centos6 ~]# make install
    3.進(jìn)階:
    Nginx核心模塊包括主模塊、事件模塊,以下這些模塊將被configure自動編譯,除非configure時(shí)指定相應(yīng)的--without。
        模塊名稱            描述                                        禁用選項(xiàng)
        Core                  控制端口,錯誤頁面別名等核心功能     --without-http
        Access                基于IP的訪問控制                     --without-http_access_module
        Auth Basic            HTTP用戶認(rèn)證模塊                     --without-http_auth_basic_module
        Auto Index            自動目錄索引                         --without-http_autoindex_module
        Browser               描述用戶代理                         --without-http_charset_module
        Charset               重新編碼網(wǎng)頁                         --without-http_charset_module
        Empty GIF             內(nèi)存中存放一個圖片                     --without-http_empty_gif_module
        FastCGI               FastCGI支持                         --without-http_fastcgi_module
        Geo                   支持IP變量設(shè)置                         --without-http_geo_module
        Gzip                  Gzip壓縮                             --without-http_gzip_module
        Headers               設(shè)置http響應(yīng)的頭部信息
        Index                 首頁
        Limit Requests        限制客戶端連接頻率                     --without-http_limit_req_module
        Limit Conn            會話的并發(fā)連接                         --without-http_limit_conn_module
        Log                   自定義日志
        Map                   設(shè)置變量                             --without-http_map_module
        Memcached             Memcache支持                         --without-http_memcached_module
        Referer               基于Referer頭部信息過濾             --without-http_referer_module
        Rewrite               使用正則表達(dá)式重寫請求                 --without-http_rewrite_module
        SCGI                  支持SGCI協(xié)議                         --without-http_scgi_module
        Upstream              負(fù)載均衡                             --without-http_upstream_ip_hash_module
       
    接下來的這些模塊屬于附加模塊,編譯軟件時(shí)需要通過configure指定開啟:
        模塊名稱            描述                                        開啟選項(xiàng)
        Embedded Perl        支持Perl                              --with-http_perl_module
        FLV                  支持flash視頻                          --with-http_flv_module
        GeoIP                通過IP變量實(shí)現(xiàn)負(fù)載均衡                  --with-http_geoip_module
        Google Perftools     支持谷歌的性能優(yōu)化工具                 --with-google_perftools_module
        Gzip Precompression  壓縮靜態(tài)文件                          --with-http_gzip_static_module
        Image Filter         轉(zhuǎn)換圖形的過濾器                      --with-http_image_filter_module
        MP4                  支持MP4                                  --with-http_mp4_module
        Real IP              使用Nginx作為后端服務(wù)器                  --with-http_realip_module
        Secure Link          使用密鑰保護(hù)頁面                      --with-http_secure_link_module
        SSL                  支持HTTPS/SSL                          --with-http_ssl_module
        Stub Status          查看服務(wù)器狀態(tài)                          --with-http_stub_status_module
        WebDAV               支持WebDAV                              --with-http_dav_module
       
    郵件模塊:
        模塊名稱            描述                                        啟用/禁用選項(xiàng)
        Core                郵件代理功能                                --with-mail
                                                                        --without-mail_pop3_module
                                                                        --without-mail_imap_module
                                                                        --without-mail_smtp_module
        Auth                郵件認(rèn)證
        Proxy               郵件代理
        SSL                 支持SSL/TLS郵件協(xié)議                        --with-mail_ssl_module
   
    第三方模塊:當(dāng)需要添加第三方模塊時(shí),同樣需要在configure時(shí)指定需要添加的模塊,格式如下。
        ./configure  --add-module=/path/module1 \
                     --add-module=/path/module2

                     ... ...
    在此介紹的模塊僅為Nginx常用模塊及描述,具體使用方法可期待后期文章... ...
   
三、控制Nginx服務(wù)
    1. 啟動服務(wù):
    [root@centos6 ~]# /usr/local/nginx/sbin/nginx
    [root@centos6 ~]# ps  aux  | grep  nginx                //查看Nginx進(jìn)程信息
    2. 停止服務(wù):
    [root@centos6 ~]# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid`
    我們可以通過傳輸信號給主進(jìn)程ID號來管理Nginx服務(wù),Nginx主進(jìn)程ID號默認(rèn)存儲在/usr/local/nginx/logs/nginx.pid文件中,
    該文件名可以通過configure修改,或者在Nginx主配置文件中通過pid指定。
        Nginx支持以下管理信號:
        信號            描述
        TERM,INT        快速關(guān)閉
        QUIT            優(yōu)雅關(guān)閉
        HUP             重新加載配置文件(等同于重啟)
        USR1            重啟加載日志文件
        USR2            升級Nginx程序
        WINCH           優(yōu)雅地關(guān)閉子工作進(jìn)程
    為了重新讀取配置文件,HUP信號必須發(fā)送給Nginx主進(jìn)程。
    主進(jìn)程首先檢查配置文件語法是否有效,再嘗試應(yīng)用新的配置,這里會重新打開日志文件并建立新的監(jiān)聽套接字,如果這個過程失敗Nginx可以回滾使用就配置文件繼續(xù)工作。
    如果成功Nginx會啟動新的工作子進(jìn)程,并發(fā)送消息給舊的工作進(jìn)程(QUIT信號),這樣舊的進(jìn)程停止監(jiān)聽服務(wù)但會繼續(xù)為當(dāng)前正在進(jìn)行的連接服務(wù),
    當(dāng)所有的就客戶連接終止后,就工作進(jìn)程被關(guān)閉。
    3. Nginx本身并未附帶啟動腳本,本著長久使用的便利性,建議將對Nginx的控制寫入腳本。篇幅有些,下一篇博客文章會專門講解這樣的啟動腳本。
   
四、基本配置
    以下為Nginx典型主配置文檔:/usr/local/nginx/conf/nginx

  1. #user  nobody;                                          //設(shè)置用戶與組 
  2. worker_processes  1;                                    //啟動進(jìn)程數(shù) 
  3. error_log  logs/error.log;                              //錯誤日志 
  4. pid        logs/nginx.pid;                              //Nginx進(jìn)程號 
  5. events { 
  6.     worker_connections  1024;                            //每個進(jìn)程的連接數(shù) 
  7. http { 
  8.     include       mime.types;                            //定義文件類型 
  9.     default_type  application/octet-stream;              //默認(rèn)文件類型 
  10.     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ' 
  11.     #                  '$status $body_bytes_sent "$http_referer" ' 
  12.     #                  '"$http_user_agent" "$http_x_forwarded_for"';
  13. //以上被注釋的log_format可以定義自己的日志格式 
  14.     #access_log  logs/access.log  main;                  //使用log_format定義的main日志格式產(chǎn)生access.log日志文件,注這里默認(rèn)是被注釋的 
  15.     sendfile        on;                                  //是否調(diào)用sendfile()進(jìn)行數(shù)據(jù)的拷貝,sendfile()拷貝數(shù)據(jù)是在內(nèi)核級別完成,所以會比一般的read,write更高效 
  16.     #tcp_nopush     on;                                  //開啟后服務(wù)器的響應(yīng)頭部信息產(chǎn)生獨(dú)立的數(shù)據(jù)包發(fā)送,即一個響應(yīng)頭信息一個包 
  17.     #keepalive_timeout  0;                               //保持連接的超時(shí)時(shí)間 
  18.     keepalive_timeout  65; 
  19.     #gzip  on;                                          //是否啟用壓縮功能,將頁面壓縮后傳輸更節(jié)省流量 
  20.     server {                                            //定義虛擬主機(jī) 
  21.     listen       80;                                    //服務(wù)器監(jiān)聽的端口 
  22.     server_name  www.jacob.com;                         //訪問域名 
  23.         #charset koi8-r;                                //頁面編碼,如果網(wǎng)頁的編碼與charset不同將被自動轉(zhuǎn)碼(轉(zhuǎn)碼后可能顯示為亂碼) 
  24.         #access_log  logs/host.access.log  main;        //設(shè)置服務(wù)器www.jacob.com的訪問日志 
  25.         location / {                                    //匹配URL地址 
  26.             root   html;                                //網(wǎng)頁根路徑,如果Nginx安裝在/usr/local/nginx目錄下,則網(wǎng)頁在/usr/local/nginx/html目錄下 
  27.             index  index.html index.htm;                //默認(rèn)首頁 
  28.         } 
  29.         #error_page  404              /404.html;        //錯誤頁面 
  30.         error_page   500 502 503 504  /50x.html; 
  31.         location = /50x.html { 
  32.             root   html; 
  33.         } 
  34.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80 
  35.         # 
  36.         #location ~ \.php$ { 
  37.         #    proxy_pass   http://127.0.0.1; 
  38.         #}                                               //以上注釋行用來設(shè)置代理,當(dāng)客戶端訪問php頁面時(shí),自動將請求轉(zhuǎn)發(fā)給后端服務(wù)器 
  39.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
  40.         # 
  41.         #location ~ \.php$ { 
  42.         #    root           html; 
  43.         #    fastcgi_pass   127.0.0.1:9000; 
  44.         #    fastcgi_index  index.php; 
  45.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name; 
  46.         #    include        fastcgi_params; 
  47.         #}                                              //以上注釋行用來設(shè)置代理,當(dāng)客戶端訪問php頁面時(shí),自動將請求轉(zhuǎn)發(fā)給后端服務(wù)器 
  48.         # deny access to .htaccess files, if Apache's document root 
  49.         # concurs with nginx's one 
  50.         # 
  51.         #location ~ /\.ht { 
  52.         #    deny  all;                                 //拒絕所有人訪問.ht頁面 
  53.         #} 
  54.     } 
  55.     # another virtual host using mix of IP-, name-, and port-based configuration 
  56.     # 
  57.     #server {                                            //定義虛擬主機(jī)(此處設(shè)置與上面一個server虛擬主機(jī)格式一樣 
  58.     #    listen       8000; 
  59.     #    listen       somename:8080; 
  60.     #    server_name  somename  alias  another.alias; 
  61.  
  62.     #    location / { 
  63.     #        root   html; 
  64.     #        index  index.html index.htm; 
  65.     #    } 
  66.     #} 
  67.     # HTTPS server 
  68.     # 
  69.     #server {                                            //定義虛擬主機(jī) 
  70.     #    listen       443; 
  71.     #    server_name  localhost; 
  72.     #    ssl                  on;                        //開啟SSL 
  73.     #    ssl_certificate      cert.pem;                  //指定證書文件 
  74.     #    ssl_certificate_key  cert.key;                  //指定私鑰文件 
  75.     #    ssl_session_timeout  5m; 
  76.     #    ssl_protocols  SSLv2 SSLv3 TLSv1; 
  77.     #    ssl_ciphers  HIGH:!aNULL:!MD5; 
  78.     #    ssl_prefer_server_ciphers   on; 
  79.     #    location / { 
  80.     #        root   html; 
  81.     #        index  index.html index.htm; 
  82.     #    } 
  83.     #} 
  84.  


   
五、示例(虛擬主機(jī)、HTTPS)
    注意:實(shí)現(xiàn)SSL需要configure時(shí)添加--with-http_ssl_module模塊
    1. 修改配置文件部分內(nèi)容如下:

  1. http { 
  2.     include       mime.types; 
  3.     default_type  application/octet-stream; 
  4.     sendfile        on; 
  5.     keepalive_timeout  65; 
  6.     gzip  on; 
  7.     server { 
  8.         listen       80; 
  9.         server_name  www.demo.com; 
  10.         charset utf-8; 
  11.         access_log  logs/demo.access.log; 
  12.         location / { 
  13.             root   demo; 
  14.             index  index.html index.htm; 
  15.         } 
  16.     } 
  17.     # HTTPS server 
  18.     server { 
  19.         listen       443; 
  20.         server_name  www.test.comm; 
  21.         ssl                  on; 
  22.         ssl_certificate      cert.cer;                //證書路徑同nginx.conf在一個目錄 
  23.         ssl_certificate_key  test.pem;                //私鑰路徑同nginx.conf在一個目錄 
  24.         ssl_session_timeout  5m; 
  25.         ssl_protocols  SSLv2 SSLv3 TLSv1; 
  26.         ssl_ciphers  HIGH:!aNULL:!MD5; 
  27.         ssl_prefer_server_ciphers   on; 
  28.         location / { 
  29.             root   test; 
  30.             index  index.html index.htm; 
  31.         } 
  32.     } 


    2. 生成證書的方法如下:
    [root@centos6 ~] openssl genrsa -out test.pem 2048                           //生成私鑰
    [root@centos6 ~] openssl req -new -x509 -key test.pem -out cert.cer          //根據(jù)私鑰生成根證書
    [root@centos6 ~] cp  {test.pem,cert,cer}  /usr/local/nginx/conf/           //拷貝證書
    效果如圖:

提示:關(guān)于密鑰與證書的操作可以參考http://manual.blog.51cto.com/3300438/788691與http://manual.blog.51cto.com/3300438/788681兩篇博文

    2. 創(chuàng)建測試用網(wǎng)頁
    [root@centos6 ~] mkdir /usr/local/nginx{demo,test}
    [root@centos6 ~] cat > /usr/local/nginx/demo/index.html  <<EOF
    > <html>
    > <title>Hello The World</title>
    > <body>
    > This is a demo page!
    > </body>
    > </html>
    > EOF

    [root@centos6 ~] cat > /usr/local/nginx/test/index.html  <<EOF
    > <html>
    > <title>Hello The World</title>
    > <body>
    > This is a demo page!
    > </body>
    > </html>
    > EOF

    3. 重啟Nginx
    [root@centos6 ~] kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
    4. 客戶端訪問(需要DNS解析或hosts文件解析)
    效果如圖:

不早了,休息了各位!

本文出自 “丁丁歷險(xiǎn)” 博客,請務(wù)必保留此出處http://manual.blog.51cto.com/3300438/948204

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Centos7搭建Nginx+Rtmp/HLS視頻直播服務(wù)端
Nginx(一):靜態(tài)資源web服務(wù)器配置詳解
Nginx實(shí)戰(zhàn)系列之功能篇
fastdfs+nginx+image安裝與生成縮略圖
基于nginx,如何搭建web的yum源?
linux 下安裝 nginx及ssl,pcre,zlib,gzip
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服