乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      nginx.conf配置——Nginx

       一本正經地胡鬧 2019-07-25

      Nginx在運行時候,至少要加載幾個核心模塊和一個事件類模塊。這些模塊運行時所支持的配置項稱為基本配置——所有其他模塊執(zhí)行時都依賴的配置項。

      由于配置項較多,所以把它們按照用戶使用時的預期功能分成以下4類:

      1. 用于調試、定位問題的配置項;
      2. 正常運行的必備配置項;
      3. 優(yōu)化性能的配置項;
      4. 事件類配置項(有些事件類配置項歸納到優(yōu)化性能類,這是因為它們雖然也屬于event{}塊,但作用是優(yōu)化性能)

      有一些配置項,幾十沒有顯式的進行配置,他們會有默認的值,如:daemon,即是在nginx.conf中沒有對它進行配置,也相當于打開了這個功能,這點需要注意。

      官網對各個模塊參數(shù)配置的解釋說明網址: Nginx中文文檔

      1. ##代碼塊中的events、http、server、location、upstream等都是塊配置項##
      2. ##塊配置項可以嵌套。內層塊直接繼承外層快,例如:server塊里的任意配置都是基于http塊里的已有配置的##
      3. ##Nginx worker進程運行的用戶及用戶組
      4. #語法:user username[groupname] 默認:user nobody nobody
      5. #user用于設置master進程啟動后,fork出的worker進程運行在那個用戶和用戶組下。當按照"user username;"設置時,用戶組名與用戶名相同。
      6. #若用戶在configure命令執(zhí)行時,使用了參數(shù)--user=usergroup 和 --group=groupname,此時nginx.conf將使用參數(shù)中指定的用戶和用戶組。
      7. #user nobody;
      8. ##Nginx worker進程個數(shù):其數(shù)量直接影響性能。
      9. #每個worker進程都是單線程的進程,他們會調用各個模塊以實現(xiàn)多種多樣的功能。如果這些模塊不會出現(xiàn)阻塞式的調用,那么,有多少CPU內核就應該配置多少個進程,反之,有可能出現(xiàn)阻塞式調用,那么,需要配置稍多一些的worker進程。
      10. worker_processes 1;
      11. ##ssl硬件加速。
      12. #用戶可以用OpneSSL提供的命令來查看是否有ssl硬件加速設備:openssl engine -t
      13. #ssl_engine device;
      14. ##守護進程(daemon)。是脫離終端在后臺允許的進程。它脫離終端是為了避免進程執(zhí)行過程中的信息在任何終端上顯示。這樣一來,進程也不會被任何終端所產生的信息所打斷。##
      15. ##關閉守護進程的模式,之所以提供這種模式,是為了放便跟蹤調試nginx,畢竟用gdb調試進程時最繁瑣的就是如何繼續(xù)跟進fork出的子進程了。##
      16. ##如果用off關閉了master_proccess方式,就不會fork出worker子進程來處理請求,而是用master進程自身來處理請求
      17. #daemon off; #查看是否以守護進程的方式運行Nginx 默認是on
      18. #master_process off; #是否以master/worker方式工作 默認是on
      19. ##error日志的設置#
      20. #語法: error_log /path/file level;
      21. #默認: error_log / log/error.log error;
      22. #當path/file 的值為 /dev/null時,這樣就不會輸出任何日志了,這也是關閉error日志的唯一手段;
      23. #leve的取值范圍是debug、info、notice、warn、error、crit、alert、emerg從左至右級別依次增大。
      24. #當level的級別為error時,error、crit、alert、emerg級別的日志就都會輸出。大于等于該級別會輸出,小于該級別的不會輸出。
      25. #如果設定的日志級別是debug,則會輸出所有的日志,這一數(shù)據量會很大,需要預先確保/path/file所在的磁盤有足夠的磁盤空間。級別設定到debug,必須在configure時加入 --with-debug配置項。
      26. #error_log logs/error.log;
      27. #error_log logs/error.log notice;
      28. #error_log logs/error.log info;
      29. ##pid文件(master進程ID的pid文件存放路徑)的路徑
      30. #pid logs/nginx.pid;
      31. events {
      32. #僅對指定的客戶端輸出debug級別的日志: 語法:debug_connection[IP|CIDR]
      33. #這個設置項實際上屬于事件類配置,因此必須放在events{……}中才會生效。它的值可以是IP地址或者是CIRD地址。
      34. #debug_connection 10.224.66.14; #或是debug_connection 10.224.57.0/24
      35. #這樣,僅僅以上IP地址的請求才會輸出debug級別的日志,其他請求仍然沿用error_log中配置的日志級別。
      36. #注意:在使用debug_connection前,需確保在執(zhí)行configure時已經加入了--with-debug參數(shù),否則不會生效。
      37. worker_connections 1024;
      38. }
      39. ##核心轉儲(coredump):在Linux系統(tǒng)中,當進程發(fā)生錯誤或收到信號而終止時,系統(tǒng)會將進程執(zhí)行時的內存內容(核心映像)寫入一個文件(core文件),以作為調試只用,這就是所謂的核心轉儲(coredump).
      40. http {
      41. ##嵌入其他配置文件 語法:include /path/file
      42. #參數(shù)既可以是絕對路徑也可以是相對路徑(相對于Nginx的配置目錄,即nginx.conf所在的目錄)
      43. include mime.types;
      44. default_type application/octet-stream;
      45. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
      46. # '$status $body_bytes_sent "$http_referer" '
      47. # '"$http_user_agent" "$http_x_forwarded_for"';
      48. #access_log logs/access.log main;
      49. sendfile on;
      50. #tcp_nopush on;
      51. #keepalive_timeout 0;
      52. keepalive_timeout 65;
      53. #gzip on;
      54. server {
      55. ##listen監(jiān)聽的端口
      56. #語法:listen address:port [ default(deprecated in 0.8.21) | default_server | [ backlog=num | rcvbuf=size | sndbuf=size | accept_filter=filter | deferred | bind | ssl ] ]
      57. #default_server: 如果沒有設置這個參數(shù),那么將會以在nginx.conf中找到的第一個server塊作為默認server塊
      58. listen 8080;
      59. #主機名稱:其后可以跟多個主機名稱,開始處理一個HTTP請求時,nginx會取出header頭中的Host,與每個server中的server_name進行匹配,以此決定到底由那一個server來處理這個請求。有可能一個Host與多個server塊中的server_name都匹配,這時會根據匹配優(yōu)先級來選擇實際處理的server塊。server_name與Host的匹配優(yōu)先級見文末。
      60. server_name localhost;
      61. #charset koi8-r;
      62. #access_log logs/host.access.log main;
      63. #location / {
      64. # root html;
      65. # index index.html index.htm;
      66. #}
      67. ##location 語法: location [=|~|~*|^~] /uri/ { ... }
      68. # location的使用實例見文末。
      69. #注意:location時有順序的,當一個請求有可能匹配多個location時,實際上這個請求會被第一個location處理。
      70. location / {
      71. proxy_pass http://192.168.1.60;
      72. }
      73. #error_page 404 /404.html;
      74. # redirect server error pages to the static page /50x.html
      75. #
      76. error_page 500 502 503 504 /50x.html;
      77. location = /50x.html {
      78. root html;
      79. }
      80. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
      81. #
      82. #location ~ \.php$ {
      83. # proxy_pass http://127.0.0.1;
      84. #}
      85. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
      86. #
      87. #location ~ \.php$ {
      88. # root html;
      89. # fastcgi_pass 127.0.0.1:9000;
      90. # fastcgi_index index.php;
      91. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
      92. # include fastcgi_params;
      93. #}
      94. # deny access to .htaccess files, if Apache's document root
      95. # concurs with nginx's one
      96. #
      97. #location ~ /\.ht {
      98. # deny all;
      99. #}
      100. }
      101. # another virtual host using mix of IP-, name-, and port-based configuration
      102. #
      103. #server {
      104. # listen 8000;
      105. # listen somename:8080;
      106. # server_name somename alias another.alias;
      107. # location / {
      108. # root html;
      109. # index index.html index.htm;
      110. # }
      111. #}
      112. # HTTPS server
      113. #
      114. #server {
      115. # listen 443 ssl;
      116. # server_name localhost;
      117. # ssl_certificate cert.pem;
      118. # ssl_certificate_key cert.key;
      119. # ssl_session_cache shared:SSL:1m;
      120. # ssl_session_timeout 5m;
      121. # ssl_ciphers HIGH:!aNULL:!MD5;
      122. # ssl_prefer_server_ciphers on;
      123. # location / {
      124. # root html;
      125. # index index.html index.htm;
      126. # }
      127. #}
      128. }

       

      server_name與Host的匹配優(yōu)先級
      首先選擇所有字符串完全匹配的server_name 如:www.testwab.com
      其次選擇通配符在前面的server_name 如:*.testwab.com
      其次選擇通配符在后面的server_name 如:www.testwab.*
      最后選擇使用正在表達式才匹配的server_name 如:~^\.testwab\.com$
      location的使用實例
      1. location = / {
      2. # matches the query / only.
      3. [ configuration A ]
      4. }
      只有當用戶請求是/時,才會使用該location下的配置
      1. location / {
      2. # matches any query, since all queries begin with /, but regular
      3. # expressions and any longer conventional blocks will be
      4. # matched first.
      5. [ configuration B ]
      6. }
      可以匹配所有請求
      1. location ^~ /images/ {
      2. # matches any query beginning with /images/ and halts searching,
      3. # so regular expressions will not be checked.
      4. [ configuration C ]
      5. }

      匹配以/images/開頭的任何查詢并停止搜索

      表示匹配URL時忽略字母大小寫問題

      1. location ~* \.(gif|jpg|jpeg)$ {
      2. # matches any request ending in gif, jpg, or jpeg. However, all
      3. # requests to the /images/ directory will be handled by
      4. # Configuration C.
      5. [ configuration D ]
      6. }

      匹配任何以gif、jpg或jpeg結尾的請求。然而,所有

      location的使用實例 —— 以root方式設置資源路徑

      location /download/ {

                 root    /opt/wab/html/;

      }          [[[意思是有一個請求的URL是 /download/index/test.html, 那么Web服務器就會返回服務器上 /opt/wab/html/download/index/test.html 文件的內容]]]

      location的使用實例 —— 以alias方式設置資源路徑

      alias也是用來設置文件資源路徑的,它與root不同點主要在于如何解讀緊跟location后面的uri參數(shù),這將會致使alias與root以不同的方式將用戶請求映射到真正的磁盤文件上。

      例如:如果有一個請求的URI是/conf/nginx.conf,而用戶實際想訪問的是 /usr/local/nginx/conf/nginx.conf,則兩種方式如下:

               alias:

                                 location  /conf {

                                                   alias    /usr/local/nginx/conf

                                }

       

              root:

                               location    /conf{

                                                  root    /usr/local/nginx

                               }

      使用alias時,在URI向實際文件路徑的映射過程中,已經把location后配置的 /conf這部分字符串丟棄掉了,因此若path中不加/conf這部分,直接映射回的地址是/usr/local/nginx/nginx.conf 與用戶實際想訪問的路徑不符。root可以放置在http、server、location或if塊中,而alias只能放置在location塊中。

      location的使用實例 —— 以index方式訪問首頁

      有時,訪問站點時的URI是/ ,這時返回網站的首頁,而這與root和alias都不同。這里用ngx_http_index_module模塊提供的index配置實現(xiàn)。index后可以跟多個文件參數(shù),Nginx將會按照順序來訪問這些文件。

      location  /?。?/p>

         root    path;

                 index   /index.html   /html/index.php          /index.php


      接受到請求后,Nginx首先會嘗試訪問path/index.php 文件,如果可以訪問,就直接返回文件內容結束請求,否則再試圖返回path/html/index.php 文件的內容,以此類推。(從后向前)

        本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
        轉藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多