1:nginx 目錄結構解析
nginx/
|-- client_body_temp
|-- conf #包含所有配置
| |-- fastcgi.conf #通用網關接口配置文件
| |-- fastcgi.conf.default #通用網關接口配置文件備份
| |-- fastcgi_params
| |-- fastcgi_params.default
| |-- koi-utf
| |-- koi-win
| |-- mime.types #支持的媒體庫類型
| |-- mime.types.default
| |-- nginx.conf #nginx服務主配置文件
| |-- nginx.conf.default
| |-- scgi_params
| |-- scgi_params.default
| |-- uwsgi_params
| |-- uwsgi_params.default
| `-- win-utf
|----fastcgi_temp
|-- html #安裝Nginx的默認站點目錄
| |-- 50x.html
| -- index.html
| ---- logs #安裝Nginx後默認的日誌目錄
| |-- access.log #訪問日誌
| |-- error.log #錯誤日誌
| -- nginx.pid
|-- proxy_temp
|-- sbin #可執行主程序文件夾
| -- nginx #Nginx主程序
|-- scgi_temp
-- uwsgi_temp
2:nginx.conf 解析
... # 全局模塊
worker_processes 1; # demo:設置主進程可以開啓幾個子進程(子進程是工作進程)
events { # nginx鏈接配置模塊(設置每一個子進程最大允許鏈接1024個鏈接)
worker_connections 1024;
}
http { # nginx http 核心配置模塊
...
server { # 爲虛擬主機配置模塊,包括監聽端口,監聽域名等
...
location { # url匹配規則
...
}
}
server {
...
}
}
nginx 全局配置參數解析
user nobody; # user 指定運行 nginx 的用戶和組(第一個參數爲用戶第二個爲組,這裏只有用戶)
worker_processes 1; # 指定工作進程數(一般設置爲CPU核數)
error_log logs/error.log; # 指定錯誤日誌爲 logs/ 目錄下的 error.log 文件
error_log logs/error.log notice; # 指定錯誤日誌,並指定寫入格式爲 notice
error_log logs/error.log info; # 指定錯誤日誌,並指定寫入格式爲 info
pid logs/nginx.pid; # 指定 pid 文件(存放主進程 pid 號)
events{} 參數解析
worker_connections 1024; # 指定每個工作進程最大連接數爲 1024
http{} 參數解析
include mime.types; # 通過 include 加載 mime.types 文件,裏面的 types {} 模塊將文件擴展名映射到響應的 MIME 類型
default_type application/octet-stream; # 定義響應的默認 MIME 類型
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; # 寫入格式 main 的內容格式如下
access_log logs/access.log main; # 指定訪問日誌和寫入格式爲 main
sendfile on; # 啓用或者禁用 sendfile()
tcp_nopush on; # 啓用或者禁用使用套接字選項(僅在 sendfile 使用時使用)
keepalive_timeout 0; # 0 值禁用保持活動的客戶端連接
keepalive_timeout 65; # 65 s 超時
gzip on; # 啓用或者禁用 gzip
server{} # 虛擬主機配置模塊
server{} 參數解析
listen 80; # 監聽 80 端口
server_name localhost; # 監聽域名爲 localhost 可以寫192.168.0.1
charset koi8-r; # 將指定的 charset 添加到 “Content-Type” 響應頭字段。如果此charset與source_charset指令中指定的charset不同,則執行轉換。
access_log logs/host.access.log main; # 指定該虛擬主機的訪問日誌
locations{; ;}
locations{; ;} 參數解析 (# 將特定的文件或目錄重新定位,如 php 文件,image 目錄等)
root html; # 設置請求的根目錄
index index.html index.htm; # 定義索引,按順序匹配