NGINX配置
@(nginx筆記)[nginx]
#運行用戶
user xxxuser xxxgroup;
#啟動進程,和CPU核心相等最好或"worker_processes auto;"自動檢測
worker_processes 1;
#worker進程最大可打開文件數(shù)據(jù)限制,默認為操作系統(tǒng)的限制
worker_rlimit_nofile 30000;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
#epoll多路復(fù)用IO中的一種方式,僅用于linux2.6以上內(nèi)核,可提高nginx性能
use epoll;
#單個后臺worker process進程的最大并發(fā)鏈接數(shù)
#并發(fā)總數(shù)是 worker_processes 和 worker_connections 的乘積
#即 max_clients = worker_processes * worker_connections
#反向代理時為 max_clients = worker_processes * worker_connections / 4
#worker_connections 值設(shè)置大小受物理內(nèi)存影響
#max_clients 并且受IO約束,值最好小于系統(tǒng)可打開最大文件句柄再適當降低
#查看當前機器配置可打開句柄數(shù) cat /proc/sys/fs/file-max
#最大連接數(shù)也受系統(tǒng)可能socket連接數(shù)限制(~64K)
worker_connections 1024;
#讓NGINX在接收到一個新連接通知后調(diào)用accept()來接受盡可能多的連接
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
#關(guān)閉版本顯示
server_tokens off;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 10;#生產(chǎn)環(huán)境決定在短時間內(nèi)用戶不會有第二次請求
#關(guān)閉不響應(yīng)的客戶端連接
reset_timedout_connection on;
#客戶端在指定時間內(nèi)沒有響應(yīng)時判定超時,關(guān)閉連接
#default = 60
send_timeout 10;
#客戶端請求頭信息以及實體信息超時未響應(yīng) NGINX返回 “Request time out 408”
#default = 均為60
client_header_timeout 10;
client_body_timeout 10;
#指定用來存儲所有訪問連接數(shù)值的共享內(nèi)存空間大小
#1m約存儲1.6W個64位的狀態(tài)
#http://nginx.org/cn/docs/http/ngx_http_limit_conn_module.html
limit_conn_zone $binary_remote_addr zone=addr:5m;
#限制每個IP同時允許的連接數(shù),從共享空間addr中讀取,否則NGINX返回 “Service unavailable 503”
#limit_conn addr 50;
#默認字符集
charset UTF-8;
#gzip
gzip on;
gzip_disable "msie6"; #對IE6關(guān)閉gzip功能
gzip_proxied any; #對所有請求類型開啟gzip
gzip_min_length 1000; #最小啟用gzpi的文件字節(jié)大小,太小文件反而不劃算 default:0
gzip_comp_level 4; #壓縮級別 1最低 9最高 default:1
#負載均衡配置
upstream loginweb {
# server 192.168.1.138:80;
server 192.168.1.133:80;
# server 192.168.1.135:80;
# server 192.168.1.136:8088;
server 127.0.0.1:808 backup;#所有負載機宕機后的展示頁
}
server {
listen 80;
server_name *.cos.com;
charset utf-8;
access_log logs/loginweb.access.log main;
#代理
location / {
proxy_pass http://loginweb;
#向后端轉(zhuǎn)發(fā)用戶來訪IP
proxy_set_header X-Real-IP $remote_addr;
#請求和后端連接超時時間,在此時間內(nèi)后端必須響應(yīng)前端握手請求
#default = 60s
proxy_connect_timeout 5;
#后端連接成功后,后端處理數(shù)據(jù)的時間
#default = 60s
proxy_read_timeout 60;
#后端數(shù)據(jù)傳回時間
#default = 60s
proxy_send_timeout 60;
#從后端讀取的第一部份應(yīng)答緩沖區(qū)大小 通知包含一個小的答應(yīng)頭
#default = 4k / 8k
#proxy_buffer_size = 4k;
#從后端讀取的數(shù)據(jù)緩存區(qū)數(shù)目和大小
#default = 8 4k/8k
proxy_buffers 8 18k;
#proxy_buffers設(shè)置的緩沖區(qū)使用完后再申請的緩沖大?。ǜ哓撦d)
#default = proxy_buffer_size * 2
proxy_busy_buffers_size 64k;
#代理緩沖區(qū)臨時文件大小
#default = proxy_buffer_size * 2
#proxy_temp_file_write_size 64k;
#代理緩沖區(qū)臨時文件最大大小
#default = 1G
proxy_max_temp_file_size 128m;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#backup站點以及狀態(tài)頁
server {
listen 808;
server_name 127.0.0.1;
access_log logs/noserver.access.log main;
location / {
root html;
index noserver.html;
}
location /status {
stub_status on;
access_log off;
allow 127.0.0.1;
allow 192.168.1.135;
deny all;
}
}
#關(guān)閉所有未綁定的默認站點
server {
listen 80 default;
return 500;
}
}