Nginx 的設定檔語法簡單,但功能極強,可以非常靈活地調配。要玩出花樣,先得看懂它長什麼樣。
nginx ├── client_body_temp ├── conf # 服務設定檔目錄 │ ├── fastcgi.conf # fastcgi 設定 │ ├── fastcgi_params # fastcgi 參數 │ ├── koi-utf / koi-win / win-utf │ ├── mime.types # MIME 類型對照 │ ├── nginx.conf # 主設定檔 │ ├── nginx.conf.default │ ├── scgi_params │ └── uwsgi_params ├── fastcgi_temp ├── html # 編譯安裝的預設首頁目錄 │ ├── 50x.html # 錯誤頁面 │ └── index.html # 預設首頁 ├── logs # 日誌目錄 │ ├── access.log # 訪問日誌 │ └── error.log # 錯誤日誌 ├── proxy_temp ├── sbin │ └── nginx # 啟動命令 ├── scgi_temp └── uwsgi_temp
用 egrep -v "#|^$" nginx.conf 濾掉註解與空行後,骨架其實一目了然:
worker_processes 1; # 工作進程數
events {
worker_connections 1024; # 每個進程的並發連接數
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server { # 虛擬主機標籤
listen 80; # 監聽埠
server_name localhost; # 主機名
location / {
root html; # 站點根目錄
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html { root html; }
}
}/application/nginx/sbin/nginx -h # 說明 nginx version: nginx/1.10.1 -v 顯示版本並退出 -V 顯示版本與編譯參數後退出 -t 檢查設定檔語法 -T 檢查並輸出設定內容 -s signal 向 master 進程送訊號:stop, quit, reopen, reload -p prefix 指定前綴路徑 -c filename 指定設定檔(預設 conf/nginx.conf) -g directives 指定全域指令
其中 -t 與 -s reload 是日常最常搭配的一組:改完設定先 -t 驗一遍,沒錯再 reload,不必重啟服務。
/application/nginx/sbin/nginx -V nginx version: nginx/1.10.1 built with OpenSSL 1.0.1e-fips 11 Feb 2013 TLS SNI support enabled configure arguments: --user=nginx --group=nginx \ --prefix=/application/nginx-1.10.1 \ --with-http_stub_status_module --with-http_ssl_module \ -with-pcre=/download/tools/pcre-8.38
這個參數在生產環境特別有用:當服務不是你親手裝的、又沒有任何文件可查時,-V 能告訴你它編入了哪些模組、支援哪些能力,省去大量猜測。
