1.全域性配置
user [使用者名稱] [組名];
示例:user nginx1 nginx;
worker_processes [工作程序數];
示例:worker_processes 4;---通常為cpu數量的1倍或2倍,可以設定成auto自動檢測
error_log [存放路徑] [存放型別]
示例:error_log logs/error.log info;
pid [存放路徑];
示例:pid logs/nginx.pid;
include [檔案路徑];
示例:include conf/nginx2.conf;
2.events配置
use [i/o模型];
示例:use epoll;---模型包括epoll(linux常用),select,poll,kqueue(windows常用)等
worker_connections [最大連線數];
示例:work_connections 1024;---表示每個work_process允許的最大連線數,預設512
3.http全域性配置
include [檔名];
default_type [**型別];
示例:include mime.types;---前端請求的資源型別
server_tokens [on | off];
示例:server_tokens off;---顯示或隱藏nginx版本,建議隱藏
access_log [服務日誌路徑檔名] [格式,可選項]
示例:access_log main;
sendfile [on | off];
示例:sendfile on;---是否使用sendfile方式傳輸檔案,普通應用設定 on ,io重負載應用設定 off
keepalive_timeout [超時時間];
示例:keepalive_timeout 120;---server端連線的保持時間,預設75秒
upstream [名稱]
示例:upstream myserver---要在server中增加proxy_pass http://myserver/;
4.server全域性配置
listen [ip:port | ip | port];
示例:listen 8080;---配置監聽的ip位址,埠號
keepalive_requests [數量];
示例:keepalive_requests 100;---單連線請求上限次數
server_name [網域名稱,可用正規表示式]
示例:server_name www.cnblog.com---設定訪問網域名稱
5.location配置
location [ = | ~ | ~* | ^~ ] uri ;
---1.'=' 標準匹配 2.『~』 正則匹配,區分大小寫 3.『~*』 正則匹配,不區分大小寫 4.『^~』 找匹配度最高的uri
示例:location ~/testweb;
proxy_pass [位址];
示例:proxy_pass http://myserver/;---設定被**伺服器的位址
rewrite [正規表示式] [位址] [flag];
示例:rewrite ^ break;---重定向到,rewrite可以用於server,location,if中;flag:last(匹配完繼續匹配),break(匹配完終止匹配),redirect(臨時重定向),permanent(永久重定向)
root [路徑];
示例:root /data/images;---接收請求後查詢的資源路徑
proxy_set_header [變數名] [變數值];
示例:proxy_set_header host $host;
proxy_set_header x-real_ip $remote_addr;
proxy_set_header x-forwarded-for &proxy_add_x_forwarded_for;---用來設定被**伺服器接收到的header資訊
【nginx配置檔案是nginx裡面很重要的一環,就將它單獨拿出來分析,參考了網上的解析,綜合起來供自己和大家**。】
Nginx配置詳解
nginx的主要配置檔案是nginx.conf,位於安裝目錄下的nginx conf資料夾裡,主要的配置引數如下 定義nginx執行的使用者和使用者組 user nobody nobody nginx程序數,建議設定為等於cpu總核心數。worker processes 8 全域性錯誤日誌定義型別,...
nginx配置詳解
定義nginx執行的使用者和使用者組 user www www nginx程序數,建議設定為等於cpu總核心數。worker processes 8 全域性錯誤日誌定義型別,debug info notice warn error crit error log var log nginx error...
NGINX配置詳解
nginx 配置檔案 user nginx 使用者worker processes 8 工作程序,根據硬體調整,大於等於cpu核數 error log logs nginx error.log crit 錯誤日誌 pid logs nginx.pid pid放置的位置 worker rlimit n...