ab -n 請求數 -c 併發數 請求url
Nginx (engine x) 是一個高性能的HTTP和反向代理服務,也是一個IMAP/POP3/SMTP服務。javascript
Mainline version 開發版(有更新的功能,但不必定穩定)
Stable version 穩定版(通過測試,有更好的穩定性)
Legacy version 歷史版本css
#運行用戶 user nobody; #啓動進程,一般設置成和cpu的數量相等 worker_processes 1; #全局錯誤日誌及PID文件 #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; #工做模式及鏈接數上限 events { #epoll是多路複用IO(I/O Multiplexing)中的一種方式, #僅用於linux2.6以上內核,能夠大大提升nginx的性能 use epoll; #單個後臺worker process進程的最大併發連接數 worker_connections 1024; # 併發總數是 worker_processes 和 worker_connections 的乘積 # 即 max_clients = worker_processes * worker_connections # 在設置了反向代理的狀況下,max_clients = worker_processes * worker_connections / 4 爲何 # 爲何上面反向代理要除以4,應該說是一個經驗值 # 根據以上條件,正常狀況下的Nginx Server能夠應付的最大鏈接數爲:4 * 8000 = 32000 # worker_connections 值的設置跟物理內存大小有關 # 由於併發受IO約束,max_clients的值須小於系統能夠打開的最大文件數 # 而系統能夠打開的最大文件數和內存大小成正比,通常1GB內存的機器上能夠打開的文件數大約是10萬左右 # 咱們來看看360M內存的VPS能夠打開的文件句柄數是多少: # $ cat /proc/sys/fs/file-max # 輸出 34336 # 32000 < 34336,即併發鏈接總數小於系統能夠打開的文件句柄總數,這樣就在操做系統能夠承受的範圍以內 # 因此,worker_connections 的值需根據 worker_processes 進程數目和系統能夠打開的最大文件總數進行適當地進行設置 # 使得併發總數小於操做系統能夠打開的最大文件數目 # 其實質也就是根據主機的物理CPU和內存進行配置 # 固然,理論上的併發總數可能會和實際有所誤差,由於主機還有其餘的工做進程須要消耗系統資源。 # ulimit -SHn 65535 } http { #設定mime類型,類型由mime.type文件定義 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; #sendfile 指令指定 nginx 是否調用 sendfile 函數(zero copy 方式)來輸出文件, #對於普通應用,必須設爲 on, #若是用來進行下載等應用磁盤IO重負載應用,可設置爲 off, #以平衡磁盤與網絡I/O處理速度,下降系統的uptime. sendfile on; #tcp_nopush on; #鏈接超時時間 #keepalive_timeout 0; keepalive_timeout 65; tcp_nodelay on; #開啓gzip壓縮 gzip on; gzip_disable "MSIE [1-6]."; #設定請求緩衝 client_header_buffer_size 128k; large_client_header_buffers 4 128k; #設定虛擬主機配置 server { #偵聽80端口 listen 80; #定義使用 www.nginx.cn訪問 server_name www.nginx.cn; #定義服務器的默認網站根目錄位置 root html; #設定本虛擬主機的訪問日誌 access_log logs/nginx.access.log main; #默認請求 location / { #定義首頁索引文件的名稱 index index.html index.htm; 若是能找到指定的 uri 那麼就返回相應的內容,不然的話返回錯誤狀態碼 404 try_files $uri $uri/ =404; } # 定義錯誤提示頁面 error_page 500 502 503 504 /50x.html; location = /50x.html { } #靜態文件,nginx本身處理 location ~ ^/(images|javascript|js|css|flash|media|static)/ { #過時30天,靜態文件不怎麼更新,過時能夠設大一點, #若是頻繁更新,則能夠設置得小一點。 expires 30d; } #禁止訪問 .htxxx 文件 location ~ /.ht { deny all; } } }
arg_PARAMETER
http_HEADER(如:http_user_agent)
sent_http_HEADERhtml
http_sub_status_module nginx客戶端的狀態(能夠配置在server和location下)java
stub_status;
具體使用結果:https://blog.csdn.net/echizao...
http_sub_module HTTP內容替換(http|server|location)node
sub_filter string(要替換的內容) replacement(替換的內容); sub_filter_once off;默認爲on 默認匹配全部內容,on只匹配一次 sub_filter_last_modified on;默認爲off 判斷服務器文件是否發生過變動,不變動則不從新加載
http_random_index_module 目錄中選擇一個隨機主頁(配置在location中)linux
random_index on;默認爲off
limit_conn_module 鏈接頻率限制nginx
limit_conn_zone key zone=name:size;(http) limit_conn zone number;(http|server|location)
limit_req_modele 請求頻率限制服務器
limit_req_zone key zone=name:size rate=rate;(http) 如:limit_req_zone $binary_remote_addr zone=req_zone:1m rate=1r/s; limit_req zone=name [burst=number](延遲數) [nodelay];(http\server\location)
http_access_module 基於ip的控制訪問(經過$remote_addr實現,代理模式就失去了做用,x-forword-for,geo模塊,自定義變量解決)網絡
allow address | CIDR(網段) | unix: | all;(http\server\location\limit_except) deny address | CIDR | unix: | all;(http\server\location\limit_except)
http_auth_basic_module 基於用戶的信任登陸(弊端解決:1結合lua實現高效驗證,2利用nginx-auth-ldap模塊,實現nginx和ldap打通)併發
auth_basic string | off;默認off(http\server\location\limit_except); auth_basic_user_file file;(http\server\location\limit_except); file爲一個用戶名密碼文件 file生成方式:htpasswd -c 文件名 用戶名 而後就會讓輸入兩次密碼 命令在httpd-tools中