#$ 開頭是變量
#定義Nginx 運行的用戶和用戶組
user work work;
#Nginx進程數, 建議設置爲CPU 總核心數
worker_processes auto;
# 指當一個Nginx 進程打開的最多文件描述符數目
worker rlimit nofile 204800;
# 全局錯誤日誌定義類型, [ debug | info | notice | warn | error | crit ]
error_log /opt/log/nginx/error.log error;
# 工作模式及連接數上限
events {
#參考事件模型, use [ kqueue | rtsig | epoll | /dev/poll | select | poll ];
#epoll 模型是Linux 2.6 以上版本內核中的高性能網絡工/ 0 模型,如果運行在FreeBSD 上面,
#就用kqueue 模型
use epoll;
#單個後臺worker process 進程的最大併發連接數
worker_connections 102400;
}
#設定http 服務器,利用它的反向代理功能提供負載均衡支持
http {
# 文件擴展名與文件類型映射表
include mime.types;
# 默認文件類型
default_type application/octet-stream;
# 默認編碼
charset utf-8;
# 設定日誌格式
#log_format main ’$idXXXX\t$remote_addr\t$remote_user\t $time_local\t$http_host\t$request\t'
# ’$status\t$body_bytes_sent\t$http_referer\t ’
# ’$http_user_agent\t$http_x_forwarded_for\t$request_time\t$upstream_response_time\t$userid’;
log_format main "$cookie_idXXXX\t$remote_addr\t$remote_user\t[$time_local]\t$request_method\t$host\t$request_uri\t”
”$request_time\t$status\t$body_bytes_sent\t’$http_referer'\t”
"'$http_user_agent’\t’$http_x_forwarded_for’\t$upstream_addr\t$upstream_response_time\t$upstream_status\t”;
# 不可見字符分隔日誌格式
#include other log forrnat.conf;
# 實時日誌收集JSON 格式日誌
#include json_log_forrnat.conf;
# 日誌流格式
log_format stream_log "$cookie_idXXXX\t$remote_addr\t$remote_user\t($time_local]\t$request_method\t$host\t$request_uri\t”
”$request_time\t$status\t$body_bytes_sent\t’$http_referer’\t" “'$http_user_agent'\t'$http_x_forwarded_for’\t$upstream_addr\t$upstream_response_time\t3”;
# 成功日誌
access_log /opt/log/nginx/access.log main;
#access_log syslog:local6:notice:logl.op.XXXXdns.org:514:nginx-main-logmain;
# 指定Nginx 是否調用sendfile 函數( zero copy 方式)來輸出文件,對於普通應用,
# 必須設爲on ,如果用來進行下載等應用磁盤I/O重負載應用,可設置爲off ,以平衡磁盤與網絡I/O處理速度,降低系統的uptime
sendfile on;
# 長連接超時時間, 單位是秒
keepalive_timeout 60;
# 服務器名稱hash 表的最大值{ 默認512)[hash%size]
server_names_hash_max_size 1024;
# 服務器名字的哈希表大小
server_names_hash_bucket_size 256;
# 客戶請求頭緩衝大小
client_header_buffer_size 4k;
# 如果header 過大,它會使用large_client_header_buffers來讀取
large_client_header_buffers 4 256k;
client_header_timeout 1m;
client_body_timeout 1m;
send_timeout 1m;
#防止網絡阻塞
tcp_nopush on;
tcp_nodelay on;
#允許客戶端請求的最大單文件字節數
client_max_body_size 50m;
# 緩衝區代理緩衝用戶端請求的最大字節數
client_body_buffer_size 50m;
#Nginx 跟後端服務器連接超時時間( 代理連接超時)
proxy_connect_timeout 5;
# 後端服務器數據回傳時間( 代理髮送超時)
proxy_send_timeout 15;
# 連接成功後, 後端服務器響應時間( 代理接收超時)
proxy_read_timeout 15;
# 設置代理服務器( Nginx )保存用戶頭信息的緩衝區大小
proxy_buffer_size 4k;
#proxy_buffers 緩衝區, 網頁平均在32KB 以下的話, 這樣設置
proxy_buffers 8 32k;
# 高負荷下緩衝大小( proxy buffers*2 )
proxy_busy_buffers size 64k;
# 設定緩存文件夾大小, 大於這個值, 將從upstream 服務器傳
proxy_temp_file_write_size 64k;
proxy_intercept_errors on;
# 客戶端放棄請求, Nginx 也放棄對後端的請求
#proxy_ignore_client_abort on;
# 代理緩存頭信息最大長度[ 設置頭部哈希表的最大值, 不能小於後端服務器設置的頭部總數]
proxy_headers_hash_max_size 512;
# 設置頭部hash表大小( 默認64 )[ 這將限制頭部字段名稱的長度大小, 如果使用超過64個字符的頭
部名可以加大這個值。]
proxy_headers_hash_bucket_size 256;
# 變量hash表的最大值( 默認值}
variables_hash_max_size 512;
# 爲變量hash 表設置關鍵字欄的大小( 默認64)
variables_hash_bucket_size 128;
# 開啓gzip 壓縮輸出
gzip on;
# 最小壓縮文件大小
gzip_min_length 1k;
# 壓縮緩衝區
gzip_buffers 4 16k;
# 壓縮等級
gzip_comp_level 9;
# 壓縮版本(默認1.1 ,前端如果是squid2.5 , 則使用1. 0 )
gzip http_version 1.0;
# 壓縮類型, 默認就已經包含texthtml
gzip_types text/plain application/x-javascript application/json application/javascript text/css application/xml text/javascript image/gif image/png;
gzip_vary on;
#map 模塊的使用
map_hash_max_size 102400;
map_hash_bucket_size 256;
#Tengine Config
#concat on;
#trim on;
#trim_css off;
#trim_js off;
server_tokens off;
#footer ”<!-- $remote_addr $server_addr $upstream_addr --> ”;
#rewrite log on;
fastcgi_intercept_errors on;
#include other config file
include .. /conf.d/*.conf;
# 包含一些特殊站點的配置文件,此目錄下文件暫時不包含在git 自動管理過程中
include .. /special/*.conf;
# 屏蔽不加主機域名的默認請求
#server {
# listen *:80 default;
# server_name _ ””;
# return 444;
#}
#Nginx 狀態監測模塊配置
req_status_zone server ” $server_name,$server_addr:$server_port" 1OM;
req_status server;
server {
listen 127.0.0.1:80;
server_name 127.0.0.1;
access_log /opt/log/nginx/nginx_status/status_access.log main;
location /status {
req_status_show;
access_log /opt/log/nginx/nginx_status/status_access.log main;
allow 127.0.0.1;
deny all;
}
location /stub_status {
stub_status on;
access_log /opt/log/nginx/nginx_status_stub/status_stub_access.
log main;
allow 127.0.0.1;
deny all;
}
location /check_status {
check_status;
access_log /opt/log/nginx/nginx_status_check/status_access_check.log main;
allow 127.0.0.1;
deny all;
}
}
}