概述
Nginx 是使用一個 master 程序來管理多個 worker 程序提供服務。master 負責管理 worker 程序,而 worker 程序則提供真正的客戶服務,worker程的數量一般跟伺服器上 CPU 的核心數相同,worker 之間通過一些程序間通信機制實作負載均衡等功能。Nginx 程序之間的關系可由下圖表示:

安裝
- Nginx版本介紹
- Mainline version - 開發版
- Stable version - 穩定版本
- Legacy version - 曆史版本
NGINX擷取位址:http://nginx.org/en/download.html
YUM安裝NGINX
#添加Nginx安裝源
#源擷取:http://nginx.org/en/linux_packages.html#RHEL-CentOS
vim /etc/yum.repos.d/nginx.repo
#添加 nginx 源
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
#----------
#檢視源 nginx 版本
yum list|grep nginx
#安裝 nginx
yum install nginx
#安裝成功後可使用此指令檢視 nginx 版本号
nginx -v
複制
Yum安裝 nginx 簡單快捷,沒有源碼安裝繁瑣.
Nginx預設安裝目錄
Nginx配置檔案規則
Nginx 服務啟動時會讀入配置檔案,後續的行為則按照配置檔案中的指令進行。Nginx 的配置檔案是純文字檔案,預設安裝 Nginx 後,其配置檔案均在usr/local/nginx/conf/ 目錄下。其中,nginx.conf 為主配置檔案。配置檔案中以 # 開始的行,或者是前面有若幹空格或者 TAB 鍵,然後再跟 #行,都被認為是注釋。這裡隻是了解主配置檔案的結構。
Nginx 配置檔案是以 block(塊)形式組織,每個 block 都是以一個塊名字和一對大括号 “{}” 表示組成,block 分為幾個層級,整個配置檔案為 mai層級,即最大的層級;在 main 層級下可以有 event、http 、mail 等層級,而 http 中又會有 server block,server block中可以包含 locatioblock。即塊之間是可以嵌套的,内層塊繼承外層塊。最基本的配置項文法格式是“配置項名 配置項值1 配置項值2 配置項值3 ... ”;
每個層級可以有自己的指令(Directive),例如 worker_processes 是一個main層級指令,它指定 Nginx 服務的 Worker 程序數量。有的指令隻能個層級中配置,如worker_processes 隻能存在于 main 中,而有的指令可以存在于多個層級,在這種情況下,子 block 會繼承 父 block 的配置,如果子block配置了與父block不同的指令,則會覆寫掉父 block 的配置。指令的格式是“指令名 參數1 參數2 … 參數N;”,注意參數間可用任意數量分隔,最後要加分号。
下圖是 Nginx 配置檔案通常結構圖示。
Nginx 服務的基本配置項
Nginx 服務運作時,需要加載幾個核心子產品和一個事件子產品,這些子產品運作時所支援的配置項稱為基本配置;基本配置項大概可分為以下四類:
- 用于調試、定位的配置項;
- 正常運作的必備配置項;
- 優化性能的配置項;
- 事件類配置項;
各個配置項的具體實作如下:
/* Nginx 服務基本配置項 */
/* 用于調試、定位的配置項 */
#以守護程序 Nginx 運作方式
#文法:daemon off | on;
#預設:daemon on;
#master / worker 工作方式
#文法:master_process on | off;
#預設:master_process on;
#error 日志設定
# 路徑 錯誤級别
#文法:error_log /path/file level;
#預設:error_log logs/error.log error;
#其中/path/file是一個具體檔案;level是日志的輸出級别,其取值如下:
# debug info notice warn error crit alert emerg
#從左至右級别增大;若設定一個級别後,則在輸出的日志檔案中隻輸出級别大于或等于已設定的級别;
#處理特殊調試點
#文法:debug_points [stop | abort]
#這個設定是來跟蹤調試 Nginx 的;
#僅對指定的用戶端輸出 debug 級别的日志
#文法:debug_connection [IP | DIR]
#限制 coredump 核心轉儲檔案的大小
#文法:worker_rlimit_core size;
#指定 coredump 檔案的生成目錄
#文法:working_directory path;
/* 正常運作的配置項 */
#定義環境變量
#文法:env VAR | VAR=VALUE;
#VAR 是變量名,VALUE 是目錄;
#嵌入其他配置檔案
#文法:include /path/file;
#include 配置項可以将其他配置檔案嵌入到 Nginx 的 nginx.conf 檔案中;
#pid 的檔案路徑
#文法:pid path/file;
#預設:pid logs/nginx.pid;
#儲存 master 程序 ID 的 pid 檔案存放路徑;
#Nginx worker 運作的使用者及使用者組
#文法:user username [groupname];
#預設:user nobody nobody;
#指定 Nginx worker程序可打開最大句柄個數
#文法:worker_rlimit_nofile limit;
#限制信号隊列
#文法:worker_rlimit_sigpending limit;
#設定每個使用者發給 Nginx 的信号隊列大小,超出則丢棄;
/* 優化性能配置項 */
#Nginx worker 程序的個數
#文法:worker_process number;
#預設:worker_process 1;
#綁定 Nginx worker 程序到指定的 CPU 核心
#文法:worker_cpu_affinity cpumask [cpumask...]
#SSL 硬體加速
#文法:ssl_engine device;
#系統調用 gettimeofday 的執行頻率
#文法:timer_resolution t;
#Nginx worker 程序優先級設定
#文法:worker_priority nice;
#預設:worker_priority 0;
/* 事件類配置項 */
#一般有以下幾種配置:
#1、是否打開accept鎖
# 文法格式:accept_mutex [on | off];
#2、lock檔案的路徑
# 文法格式:lock_file path/file;
#3、使用accept鎖後到真正建立連接配接之間的延遲時間
# 文法格式:accept_mutex_delay Nms;
#4、批量建立新連接配接
# 文法格式:multi_accept [on | off];
#
#5、選擇事件模型
# 文法格式:use [kqueue | rtisg | epoll | /dev/poll | select | poll | eventport];
#6、每個worker進行的最大連接配接數
# 文法格式:worker_connections number;
複制
HTTP 核心子產品的配置
具體可以參看《Nginx 中 HTTP 核心子產品配置》
/* HTTP 核心子產品配置的功能 */
/* 虛拟主機與請求分發 */
#監聽端口
#文法:listen address:port[default | default_server | [backlong=num | rcvbuf=size | sndbuf=size |
# accept_filter | deferred | bind | ipv6only=[on | off] | ssl]];
# 預設:listen:80;
# 說明:
# default或default_server:将所在的server塊作為web服務的預設server塊;當請求無法比對配置檔案中的所有主機名時,就會選擇預設的虛拟主機;
# backlog=num:表示 TCP 中backlog隊列存放TCP新連接配接請求的大小,預設是-1,表示不予設定;
# rcvbuf=size:設定監聽句柄SO_RCVBUF的參數;
# sndbuf=size:設定監聽句柄SO_SNDBUF的參數;
# accept_filter:設定accept過濾器,隻對FreeBSD作業系統有用;
# deferred:設定該參數後,若使用者發起TCP連接配接請求,并且完成TCP三向交握,但是若使用者沒有發送資料,則不會喚醒worker程序,直到發送資料;
# bind:綁定目前端口 / 位址對,隻有同時對一個端口監聽多個位址時才會生效;
# ssl:在目前端口建立的連接配接必須基于ssl協定;
#配置塊範圍:server
#主機名稱
#文法:server_name name[...];
#預設:server_name "";
#配置塊範圍:server
#server name 是使用散清單存儲的
#每個散列桶占用記憶體大小
#文法:server_names_hash_bucket_size size;
#預設:server_names_hash_bucker_size 32|64|128;
#
#散清單最大bucket數量
#文法:server_names_hash_max_size size;
#預設:server_names_hash_max_size 512;
#預設:server_name_in_redirect on;
#配置塊範圍:server、http、location
#處理重定向主機名
#文法:server_name_in_redirect on | off;
#預設:server_name_in_redirect on;
#配置塊範圍:server、http、location
#location文法:location[= | ~ | ~* | ^~ | @] /uri/ {}
#配置塊範圍:server
#location嘗試根據使用者請求中的URI來比對 /uri表達式,若比對成功,則執行{}裡面的配置來處理使用者請求
#以下是location的一般配置項
#1、以root方式設定資源路徑
# 文法格式:root path;
#2、以alias方式設定資源路徑
# 文法格式:alias path;
#3、通路首頁
# 文法格式:index file...;
#4、根據HTTP傳回碼重定向頁面
# 文法格式:error_page code [code...] [= | =answer-code] uri | @named_location;
#5、是否允許遞歸使用error_page
# 文法格式:recursive_error_pages [on | off];
#6、try_files
# 文法格式:try_files path1 [path2] uri;
/* 檔案路徑的定義 */
#root方式設定資源路徑
#文法:root path;
#預設:root html;
#配置塊範圍:server、http、location、if
#以alias方式設定資源路徑
#文法:alias path;
#配置塊範圍:location
#通路首頁
#文法:index file...;
#預設:index index.html;
#配置塊範圍:http、server、location
#根據HTTP傳回碼重定向頁面
# 文法:error_page code [code...] [= | =answer-code] uri | @named_location;
#配置塊範圍:server、http、location、if
#是否允許遞歸使用error_page
# 文法:recursive_error_pages [on | off];
#配置塊範圍:http、server、location
#try_files
# 文法:try_files path1 [path2] uri;
#配置塊範圍:server、location
/* 記憶體及磁盤資源配置設定 */
# HTTP 包體隻存儲在磁盤檔案中
# 文法:client_body_in_file_only on | clean | off;
# 預設:client_body_in_file_only off;
# 配置塊範圍:http、server、location
# HTTP 包體盡量寫入到一個記憶體buffer中
# 文法:client_body_single_buffer on | off;
# 預設:client_body_single_buffer off;
# 配置塊範圍:http、server、location
# 存儲 HTTP 頭部的記憶體buffer大小
# 文法:client_header_buffer_size size;
# 預設:client_header_buffer_size 1k;
# 配置塊範圍:http、server
# 存儲超大 HTTP 頭部的記憶體buffer大小
# 文法:large_client_header_buffer_size number size;
# 預設:large_client_header_buffer_size 4 8k;
# 配置塊範圍:http、server
# 存儲 HTTP 包體的記憶體buffer大小
# 文法:client_body_buffer_size size;
# 預設:client_body_buffer_size 8k/16k;
# 配置塊範圍:http、server、location
# HTTP 包體的臨時存放目錄
# 文法:client_body_temp_path dir-path [level1 [level2 [level3]]];
# 預設:client_body_temp_path client_body_temp;
# 配置塊範圍:http、server、location
# 存儲 TCP 成功建立連接配接的記憶體池大小
# 文法:connection_pool_size size;
# 預設:connection_pool_size 256;
# 配置塊範圍:http、server
# 存儲 TCP 請求連接配接的記憶體池大小
# 文法:request_pool_size size;
# 預設:request_pool_size 4k;
# 配置塊範圍:http、server
/* 網絡連接配接設定 */
# 讀取 HTTP 頭部的逾時時間
# 文法:client_header_timeout time;
# 預設:client_header_timeout 60;
# 配置塊範圍:http、server、location
# 讀取 HTTP 包體的逾時時間
# 文法:client_body_timeout time;
# 預設:client_body_timeout 60;
# 配置塊範圍:http、server、location
# 發送響應的逾時時間
# 文法:send_timeout time;
# 預設:send_timeout 60;
# 配置塊範圍:http、server、location
# TCP 連接配接的逾時重置
# 文法:reset_timeout_connection on | off;
# 預設:reset_timeout_connection off;
# 配置塊範圍:http、server、location
# 控制關閉 TCP 連接配接的方式
# 文法:lingering_close off | on | always;
# 預設:lingering_close on;
# 配置塊範圍:http、server、location
# always 表示關閉連接配接之前無條件處理連接配接上所有使用者資料;
# off 表示不處理;on 一般會處理;
# lingering_time
# 文法:lingering_time time;
# 預設:lingering_time 30s;
# 配置塊範圍:http、server、location
# lingering_timeout
# 文法:lingering_timeout time;
# 預設:lingering_time 5s;
# 配置塊範圍:http、server、location
# 對某些浏覽器禁止keepalive功能
# 文法:keepalive_disable [mise6 | safari | none]...
# 預設:keepalive_disable mise6 safari;
# 配置塊範圍:http、server、location
# keepalive逾時時間
# 文法:keepalive_timeout time;
# 預設:keepalive_timeout 75;
# 配置塊範圍:http、server、location
# keepalive長連接配接上允許最大請求數
# 文法:keepalive_requests n;
# 預設:keepalive_requests 100;
# 配置塊範圍:http、server、location
# tcp_nodelay
# 文法:tcp_nodelay on | off;
# 預設:tcp_nodelay on;
# 配置塊範圍:http、server、location
# tcp_nopush
# 文法:tcp_nopush on | off;
# 預設:tcp_nopush off;
# 配置塊範圍:http、server、location
/* MIME 類型設定 */
# MIME type 與檔案擴充的映射
# 文法:type{...}
# 配置塊範圍:http、server、location
# 多個擴充名可映射到同一個 MIME type
# 預設 MIME type
# 文法:default_type MIME-type;
# 預設:default_type text/plain;
# 配置塊範圍:http、server、location
# type_hash_bucket_size
# 文法:type_hash_bucket_size size;
# 預設:type_hash_bucket_size 32 | 64 | 128;
# 配置塊範圍:http、server、location
# type_hash_max_size
# 文法:type_hash_max_size size;
# 預設:type_hash_max_size 1024;
# 配置塊範圍:http、server、location
/* 限制用戶端請求 */
# 按 HTTP 方法名限制使用者請求
# 文法:limit_except method...{...}
# 配置塊:location
# method 的取值如下:
# GET、HEAD、POST、PUT、DELETE、MKCOL、COPY、MOVE、OPTIONS、
# PROPFIND、PROPPATCH、LOCK、UNLOCK、PATCH
# HTTP 請求包體的最大值
# 文法:client_max_body_size size;
# 預設:client_max_body_size 1m;
# 配置塊範圍:http、server、location
# 對請求限制速度
# 文法:limit_rate speed;
# 預設:limit_rate 0;
# 配置塊範圍:http、server、location、if
# 0 表示不限速
# limit_rate_after規定時間後限速
# 文法:limit_rate_after time;
# 預設:limit_rate_after 1m;
# 配置塊範圍:http、server、location、if
/* 檔案操作的優化 */
# sendfile系統調用
# 文法:sendfile on | off;
# 預設:sendfile off;
# 配置塊:http、server、location
# AIO 系統調用
# 文法:aio on | off;
# 預設:aio off;
# 配置塊:http、server、location
# directio
# 文法:directio size | off;
# 預設:directio off;
# 配置塊:http、server、location
# directio_alignment
# 文法:directio_alignment size;
# 預設:directio_alignment 512;
# 配置塊:http、server、location
# 打開檔案緩存
# 文法:open_file_cache max=N [inactive=time] | off;
# 預設:open_file_cache off;
# 配置塊:http、server、location
# 是否緩存打開檔案的錯誤資訊
# 文法:open_file_cache_errors on | off;
# 預設:open_file_cache_errors off;
# 配置塊:http、server、location
# 不被淘汰的最小通路次數
# 文法:open_file_cache_min_user number;
# 預設:open_file_cache_min_user 1;
# 配置塊:http、server、location
# 檢驗緩存中元素有效性的頻率
# 文法:open_file_cache_valid time;
# 預設:open_file_cache_valid 60s;
# 配置塊:http、server、location
/* 客戶請求的特殊處理 */
# 忽略不合法的 HTTP 頭部
# 文法:ignore_invalid_headers on | off;
# 預設:ignore_invalid_headers on;
# 配置塊:http、server
# HTTP 頭部是否允許下劃線
# 文法:underscores_in_headers on | off;
# 預設:underscores_in_headers off;
# 配置塊:http、server
# If_Modified_Since 頭部的處理政策
# 文法:if_modified_since [off | exact | before]
# 預設:if_modified_since exact;
# 配置塊:http、server、location
# 檔案未找到時是否記錄到error日志
# 文法:log_not_found on | off;
# 預設:log_not_found on;
# 配置塊:http、server、location
# 是否合并相鄰的“/”
# 文法:merge_slashes on | off;
# 預設:merge_slashes on;
# 配置塊:http、server、location
# DNS解析位址
# 文法:resolver address...;
# 配置塊:http、server、location
# DNS解析的逾時時間
# 文法:resolver_timeout time;
# 預設:resolver_timeout 30s;
# 配置塊:http、server、location
# 傳回錯誤頁面是否在server中注明Nginx版本
# 文法:server_tokens on | off;
# 預設:server_tokens on;
# 配置塊:http、server、location
複制
以下是在 Ubuntu 12.04 系統成功安裝 Nginx 之後的主配置檔案:
#Nginx伺服器正常啟動時會讀取該配置檔案,以下的值都是預設的,若需要可自行修改;
#以下是配置選項
#Nginx worker程序運作的使用者以及使用者組
#文法格式:user username[groupname]
#user nobody;
#Nginx worker 程序個數
worker_processes 1;
#error 日志設定
#文法格式:error /path/file level
#其中/path/file是一個具體檔案;level是日志的輸出級别,其取值如下:
#debug info notice warn error crit alert emerg,從左至右級别增大;
#若設定一個級别後,則在輸出的日志檔案中隻輸出級别大于或等于已設定的級别;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#儲存master程序ID的pid檔案存放路徑
#文法格式:pid path/file
#pid logs/nginx.pid;
#事件類配置項
#一般有以下幾種配置:
#1、是否打開accept鎖
# 文法格式:accept_mutex [on | off];
#2、lock檔案的路徑
# 文法格式:lock_file path/file;
#3、使用accept鎖後到真正建立連接配接之間的延遲時間
# 文法格式:accept_mutex_delay Nms;
#4、批量建立新連接配接
# 文法格式:multi_accept [on | off];
#5、選擇事件模型
# 文法格式:use [kqueue | rtisg | epoll | /dev/poll | select | poll | eventport];
#6、每個worker進行的最大連接配接數
# 文法格式:worker_connections number;
events {
worker_connections 1024;
}
#以下是http子產品
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;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#server塊
# 每個server塊就是一個虛拟主機,按照server_name來區分
server {
#監聽端口
listen 80;
#主機名稱
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#location文法:location[= | ~ | ~* | ^~ | @] /uri/ {}
#location嘗試根據使用者請求中的URI來比對 /uri表達式,若比對成功,則執行{}裡面的配置來處理使用者請求
#以下是location的一般配置項
#1、以root方式設定資源路徑
# 文法格式:root path;
#2、以alias方式設定資源路徑
# 文法格式:alias path;
#3、通路首頁
# 文法格式:index file...;
#4、根據HTTP傳回碼重定向頁面
# 文法格式:error_page code [code...] [= | =answer-code] uri | @named_location;
#5、是否允許遞歸使用error_page
# 文法格式:recursive_error_pages [on | off];
#6、try_files
# 文法格式:try_files path1 [path2] uri;
location / {
root html;
index index.html index.htm;
}
#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;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
複制
Nginx的内置變量
内置變量存放在
ngx_http_core_module
子產品中,變量的命名方式和apache 伺服器變量是一緻的。總而言之,這些變量代表着用戶端請求頭的内容,例如
$http_user_agent
,
$http_cookie
, 等等。下面是nginx支援的所有内置變量:
變量 | 解釋 |
---|---|
$arg_name | 請求中的的參數名,即“?”後面的arg_name=arg_value形式的arg_name |
$args | 請求中的參數值 |
$binary_remote_addr | 用戶端位址的二進制形式, 固定長度為4個位元組 |
$body_bytes_sent | 傳輸給用戶端的位元組數,響應頭不計算在内;這個變量和Apache的mod_log_config子產品中的“%B”參數保持相容 |
$bytes_sent | 傳輸給用戶端的位元組數 (1.3.8, 1.3.5) |
$connection | TCP連接配接的序列号 (1.3.8, 1.2.5) |
$connection_requests | TCP連接配接目前的請求數量 (1.4.8, 1.2.5) |
$content_length | “Content-Length” 請求頭字段 |
$content_type | “Content-Type” 請求頭字段 |
$cookie_name | cookie名稱 |
$document_root | 目前請求的文檔根目錄或别名 |
$document_uri | 同 $uri |
$host | 優先級如下:HTTP請求行的主機名>”HOST”請求頭字段>符合請求的伺服器名 |
$hostname | 主機名 |
$http_name | 比對任意請求頭字段; 變量名中的後半部分“name”可以替換成任意請求頭字段,如在配置檔案中需要擷取http請求頭:“Accept-Language”,那麼将“-”替換為下劃線,大寫字母替換為小寫,形如:$http_accept_language即可。 |
$https | 如果開啟了SSL安全模式,值為“on”,否則為空字元串。 |
$is_args | 如果請求中有參數,值為“?”,否則為空字元串。 |
$limit_rate | 用于設定響應的速度限制,詳見 limit_rate。 |
$msec | 目前的Unix時間戳 (1.3.9, 1.2.6) |
$nginx_version | nginx版本 |
$pid | 工作程序的PID |
$pipe | 如果請求來自管道通信,值為“p”,否則為“.” (1.3.12, 1.2.7) |
$proxy_protocol_addr | 擷取代理通路伺服器的用戶端位址,如果是直接通路,該值為空字元串。(1.5.12) |
$query_string | 同 $args |
$realpath_root | 目前請求的文檔根目錄或别名的真實路徑,會将所有符号連接配接轉換為真實路徑。 |
$remote_addr | 用戶端位址 |
$remote_port | 用戶端端口 |
$remote_user | 用于HTTP基礎認證服務的使用者名 |
$request | 代表用戶端的請求位址 |
$request_body | 用戶端的請求主體;此變量可在location中使用,将請求主體通過proxy_pass, fastcgi_pass, uwsgi_pass, 和 scgi_pass傳遞給下一級的代理伺服器。 |
$request_body_file | 将用戶端請求主體儲存在臨時檔案中。檔案處理結束後,此檔案需删除。如果需要之一開啟此功能,需要設定client_body_in_file_only。如果将次檔案傳遞給後端的代理伺服器,需要禁用request body,即設定proxy_pass_request_body off,fastcgi_pass_request_body off,uwsgi_pass_request_body off, or scgi_pass_request_body off 。 |
$request_completion | 如果請求成功,值為”OK”,如果請求未完成或者請求不是一個範圍請求的最後一部分,則為空。 |
$request_filename | 目前連接配接請求的檔案路徑,由root或alias指令與URI請求生成。 |
$request_length | 請求的長度 (包括請求的位址, http請求頭和請求主體) (1.3.12, 1.2.7) |
$request_method | HTTP請求方法,通常為“GET”或“POST” |
$request_time | 處理用戶端請求使用的時間 (1.3.9, 1.2.6); 從讀取用戶端的第一個位元組開始計時。 |
$request_uri | 這個變量等于包含一些用戶端請求參數的原始URI,它無法修改,請檢視$uri更改或重寫URI,不包含主機名,例如:”/cnphp/test.php?arg=freemouse”。 |
$scheme | 請求使用的Web協定, “http” 或 “https” |
$sent_http_name | 可以設定任意http響應頭字段; 變量名中的後半部分“name”可以替換成任意響應頭字段,如需要設定響應頭Content-length,那麼将“-”替換為下劃線,大寫字母替換為小寫,形如:$sent_http_content_length 4096即可。 |
$server_addr | 伺服器端位址,需要注意的是:為了避免通路linux系統核心,應将ip位址提前設定在配置檔案中。 |
$server_nam | 伺服器名,www.i7dom.cn |
$server_por | 伺服器端口 |
$server_protoco | 伺服器的HTTP版本, 通常為 “HTTP/1.0” 或 “HTTP/1.1” |
$status | HTTP響應代碼 (1.3.2, 1.2.2) |
$tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, $tcpinfo_rcv_space | 用戶端TCP連接配接的具體資訊 |
$time_iso860 | 伺服器時間的ISO 8610格式 (1.3.12, 1.2.7) |
$time_loca | 伺服器時間(LOG Format 格式) (1.3.12, 1.2.7) |
$uri | 請求中的目前URI(不帶請求參數,參數位于$args),可以不同于浏覽器傳遞的$request_uri的值,它可以通過内部重定向,或者使用index指令進行修改,$uri不包含主機名,如”/foo/bar.html”。 |
參考資料:
《Nginx子產品開發入門》
《Nginx開發從入門到精通》
版權屬于:龍之介大人