nginx配置文件詳解

#就nginx的配置文件nginx.conf進行詳細說明:

user                      admin admin;

#定義nginx運行的用戶和用戶組

worker_processes                        8;

#nginx的運行進程數,建議設置等於cpu的總核心數,一般是8


pid             /export/servers/nginx/run/nginx.pid;

#進程pid的的文件

worker_rlimit_nofile                    65535;

#一個nginx進程應許打開的最大文件數。

events 

{

use epoll;

#參考事件模型,use [ kqueue | rtsig | epoll | /dev/poll | select | poll ]; epoll模型

是Linux 2.6以上版本內核中的高性能網絡I/O模型,如果跑在FreeBSD上面,就用kqueue模型。

worker_connections 65535;

#單個進程的最大連接數

}

http 

#設定http服務器,利用它的反向代理功能提供負載均衡支持

{

include                         mime.types;

#設定mime類型,類型由mime.types文件定義

default_type                    application/octet-stream;

#默認文件類型

server_tokens                   on;

#nginx在調用的時候,可以知道nginx的版本信息

log_format main            '$remote_addr - $remote_user [$time_local] '

                    #記錄客戶端的ip,客戶端用戶名稱,訪問時間和時區

                      '"$request" $status $bytes_sent ' 

                #用來記錄請求的url與http協議,狀態(200成功),發送客戶端文件大小

                           '"$http_referer" "$http_user_agent" '

            #記錄從哪個頁面鏈接訪問過來了,記錄客戶端瀏覽器的相關信息

                      '"$request_time $upstream_response_time $pipe" '

            #求情相應時間,upstream請求相應時間,

                           '"$gzip_ratio"';

            #設定日誌格式

charset                        utf-8;

#默認的編碼字符集

server_names_hash_bucket_size   128;

#服務器名字的hash表的大小

client_header_buffer_size       32k;

#上傳文件大小限制

large_client_header_buffers     4 32k;

#設定請求緩存

#nginx默認會用client_header_buffer_size這個buffer來讀取header值,如果header過大,它會使用large_client_header_buffers來讀取,如果設置過小HTTP頭/Cookie過大 會報400 錯誤即:nginx 400 bad request。求行如果超過buffer,就會報HTTP 414錯誤(URI Too Long)nginx接受最長的HTTP頭部大小必須比其中一個buffer大,否則就會報400的,HTTP錯誤(Bad Request)。

client_max_body_size            300m;

client_body_buffer_size         512k;

#設定請求緩存

sendfile                        on;

#開啓高效文件傳輸模式,sendfile指令指定nginx是否調用sendfile函數來輸出文件,對於普通應用設爲on

tcp_nopush                      on;

#防止網絡堵塞

tcp_nodelay                     on;

#防止網絡堵塞

keepalive_timeout               0;

#長鏈接超時時間,單位是秒

#fastcgi相關參數是爲了改善網站性能;減少資源佔用,提高訪問速率

fastcgi_intercept_errors        on;

#指定是否傳遞4xx和5xx錯誤信息到客戶端,或者允許nginx使用error_page處理錯誤信息


#利用proxy模塊給nginx加入緩存,提高http的相應請求效率

proxy_connect_timeout           90;

#後端服務器連接超時的時間,發起握手等候響應超時時間,

proxy_read_timeout              180;

#連接成功後,後端服務器處理請求的時間

proxy_send_timeout              180;

#在180秒內,後端服務器必須傳完所有數據

proxy_buffer_size               256k;

#通常情況下,這部分被設置爲第一部分應答的緩存區的大小,這個是應答頭的大小

proxy_buffers                   4 256k;

#緩存區的大小

proxy_busy_buffers_size         256k;

#高負荷下緩衝大小(proxy_buffers*2)

proxy_temp_file_write_size      256k;

#設置在寫入proxy_temp_path時數據的大小,預防一個工作進程在傳遞文件時阻塞太長

proxy_intercept_errors          on;

#設置客戶端應許看到緩存的出錯信息

proxy_hide_header       X-Powered-By;

#隱藏不必要的頭,減少數據傳輸

    server_name_in_redirect         off;

#讓 nginx 在處理自己內部重定向時不默認使用  server_name 設置中的第一個域名;


gzip                            on;

#開啓gzip壓縮傳輸

gzip_min_length                 100;

#最小壓縮文件大小

gzip_buffers                    4 16k;

#壓縮緩衝區

gzip_http_version               1.0;

#壓縮版本

gzip_comp_level                 9;

#壓縮級別

gzip_types        text/plain application/x-javascript text/css application/xml;

#壓縮類型

gzip_vary                       on;

error_page 400 401 402 403 404 405 408 410 412 413 414 415 500 501 502 503 506 = http://www.jd.com/error2.aspx;

lua_package_path '/export/servers/nginx/var/lua/?/?.lua;/export/servers/nginx/var/lua/?.lua;;';

#lua腳本

include domains/*.upstream.conf;

#nginx的upstream模塊,負載均衡主要通過這個模塊實現

####### server ##########

server

{

listen                 80;

#監聽的端口

         server_name    shpls.wms5.jd.com;

#第一個域名

access_log             /export/servers/nginx/logs/access.log main;

#訪問日誌

error_log              /export/servers/nginx/logs/error.log warn;

#錯誤日誌,error_log 級別分爲 debug, info, notice, warn, error, crit  默認爲crit, 該級別在日誌名後邊定義格式如下:error_log  /your/path/error.log crit;  crit 記錄的日誌最少,而debug記錄的日誌最多。如果你的nginx遇到一些問題,比如502比較頻繁出現,但是看默認的error_log並沒有看到有意義的信息,那麼就可以調一下錯誤日誌的級別,當你調成error級別時,錯誤日誌記錄的內容會更加豐富。

location / {

#access_log             on;

root html;

index index.html index.htm;

}

location = /status {

stub_status on;

access_log off;

}

include domains/*.location.conf;

location ^~ /winapp/ {

root /export/App/app.wms5.jd.local;

index ReleaseList.xml;

}

location ^~ /rfapp/ {

root /export/App/app.wms5.jd.local;

index ReleaseList.xml;

}

location ~ ^/([^/]+)/.+ {

set $wms_app_module $1;

rewrite ^/\w+/(.+)$ /$1 break;

content_by_lua_file /export/servers/nginx/var/lua/approute.lua;

}

}

}


1、日誌格式說明解釋
 1.$remote_addr 與$http_x_forwarded_for 用以記錄客戶端的ip地址;
 2.$remote_user :用來記錄客戶端用戶名稱;
 3.$time_local : 用來記錄訪問時間與時區;
 4.$request : 用來記錄請求的url與http協議;
 5.$status : 用來記錄請求狀態;成功是200,
 6.$body_bytes_s ent :記錄發送給客戶端文件主體內容大小;
 7.$http_referer :用來記錄從那個頁面鏈接訪問過來的;
 8.$http_user_agent :記錄客戶端瀏覽器的相關信息;

2.uptream模塊說明

3.location陌路愛說明

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章