### For more information on configuration, see: ### * Official English Documentation: ##nginx運行用戶 user nginx; ##pid路徑 pid /run/nginx.pid; ##nginx工做的線程數,auto根據本機cpu顆粒數自動適配. worker_processes auto; ##一個nginx進程打開的最多文件描述符數目,與ulimit -n(系統每一個進程可打開的文件數)的值保持一致. worker_rlimit_nofile 65535; ##events模塊中包含nginx中全部處理鏈接的設置. events { ##一個worker進程同時打開的最大鏈接數,由系統的可用socket鏈接數限制. worker_connections 51200; ##當nginx接到新鏈接的請求時,會盡量的接受更多的鏈接 multi_accept on; ##Linux2.6+,性能最好的多路IO複用客戶端線程的輪詢方法. use epoll; } ##HTTP模塊控制着nginx之http處理的全部核心特性. http { ##加載MIME類型 include /etc/nginx/mime.types; ##設置文件使用的默認的MIME-type default_type text/html; ##設置頭文件中的默認的字符集 charset UTF-8; ##關閉錯誤頁面nginx版本號顯示,於安全有益. server_tokens off; ##sendfile減小拷貝文件過程,實現高效數據傳輸 sendfile on; ##當使用sendfile函數時,tcp_nopush才起做用,一個數據包裏發送全部頭文件,而不一個接一個的發送 ##它是Nagle算法的進一步加強,即阻塞數據包發送. ##Tcp_nopush選項會讓nginx嘗試在一個packet內發送其HTTP響應,而不是分幀傳送##對優化吞吐率頗有用處 tcp_nopush on; ##禁用Nagle算法,益於大量數據的通訊性能. tcp_nodelay on; ##關閉日誌,減小IO # access_log off; # log_format main '[$time_local] ' '$request_uri ' '$status $upstream_addr $upstream_status ' '$upstream_response_time $request_time'; log_format cache '[$time_local] ' '$request_uri ' '$status $upstream_addr $upstream_status ' '$upstream_response_time $request_time'; # access_log /var/log/nginx/access.log main; ##設置錯誤日誌路徑和文件名 error_log /var/log/nginx/error.log; ##當被代理的後端服務器的響應狀態碼大於等於300時,將響應轉發給nginx由error_page指令來處理. proxy_intercept_errors on; ##自定義錯誤頁面 error_page 404 http://xxx.com/error/404.html; error_page 500 502 503 504 http://xxx.com/error/soHot.html; ##keep-alive鏈接的超時時間,server會在此時間以後關閉鏈接 keepalive_timeout 13; ##client的請求能夠轉換成keep-alive鏈接的數量,影響性能測試,默認100 # keepalive_requests 65535; ##容許server在client中止響應之後關閉鏈接,釋放分配給該鏈接的內存 reset_timedout_connection on; ##若是client中止讀取數據,在此時間之後釋放該鏈接,默認是60秒 send_timeout 6; ##設置用於保存各類key(好比當前鏈接數)的共享內存的參數 limit_conn_zone $binary_remote_addr zone=addr:24m ; ##爲給定的key設置最大鏈接數,即一個IP地址最多同時打開鏈接數 limit_conn addr 51200; ##採用gzip壓縮的形式發送數據 gzip on; ##爲指定的客戶端禁用gzip功能 gzip_disable "msie6"; ##壓縮全部的請求 gzip_proxied any; ##設置對數據啓用壓縮的最少字節數,少於1000字節不壓縮 gzip_min_length 1000; ##壓縮級別 gzip_comp_level 6; ##設置須要壓縮的數據格式 gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/jpeg image/gif image/png image/jpg application/x-javascript image/svg+xml application/x-font-ttf application/vnd.ms-fontobject; ##緩存最大數目,以及緩存的時間 open_file_cache max=100000 inactive=20s; ##更新間隔時間 open_file_cache_valid 30s; ##inactive參數時間內文件的最少使用次數,若是超過這個數字,緩存一直存在 open_file_cache_min_uses 2; ##搜索文件時是否緩存錯誤信息,再次給配置中添加文件 open_file_cache_errors on;# proxy_next_upstream off; ##肯定在何種狀況下請求將轉發到下一個服務器。轉發請求只發生在沒有數據傳遞到客戶端的過程當中##[error|timeout|invalid_header|http_500|http_502|http_503|http_504|http_404|off]##表示只負載一臺機器,若是超時則返回,不去輪詢其餘機器 proxy_next_upstream_tries 1; ##nginx上傳文件大小限制,默認值1M client_max_body_size 10m; client_body_buffer_size 128k; ##若是client對於body的請求超過這個時間,則發送"request timed out"響應,默認60秒##防範慢查詢*** client_body_timeout 10; client_header_timeout 10; #nginx跟後端服務器鏈接超時時間(代理鏈接超時) proxy_connect_timeout 13; proxy_send_timeout 21; #後端服務器數據回傳時間(代理髮送超時) proxy_read_timeout 34; #鏈接成功後,後端服務器響應時間(代理接收超時) proxy_buffer_size 64k; #設置代理服務器(nginx)保存用戶頭信息的緩衝區大小 proxy_buffers 4 64k; #proxy_buffers緩衝區,網頁平均在32k如下 proxy_busy_buffers_size 128k; #高負荷下緩衝大小(proxy_buffers*2) proxy_temp_file_write_size 256k; #設定緩存文件夾大小,大於這個值,將從upstream服務器傳 #當文件超過該參數設置的大小時,nginx會先將文件寫入臨時目錄(默認爲nginx安裝目下/proxy_temp目錄),注意權限問題 server_names_hash_bucket_size 128; client_header_buffer_size 64k; large_client_header_buffers 4 128k;