Nginx安裝echo模組,nginxecho模組
1、下載需要的echo模組
https://github.com/openresty/echo-nginx-module/tags
# wget https://github.com/openresty/echo-nginx-module/archive/v0.60.tar.gz
# tar zxvf v0.60.tar.gz
# mv echo-nginx-module-0.60 tools/
2、安裝nginx
# wget http://nginx.org/download/nginx-1.10.1.tar.gz
# tar -zxvf nginx-1.10.1.tar.gz
# /application/nginx/sbin/nginx -V #查看已經安裝過的模組
3、安裝echo-nginx模組
# ./configure --add-module=/root/tools/echo-nginx-module-0.60 #安裝echo模組(檔案夾名echo-nginx-module-0.60)
# make #開始編譯,但別安裝 (make install會直接覆蓋安裝)
注意先備份一下之前老的,手動安裝一下。
# mv /application/nginx/sbin/nginx /application/nginx/sbin/nginx.old
# make upgrade #平滑升級
# make install #全新安裝
# make clean #(清除操作,可以忽略)
4、ngix_echo模組的使用
location /echo {
default_type text/html;
set $foo 'hello world'; #自訂變數
echo "$request_uri"; #顯示nginx全域變數的內容
echo </br>$foo; #顯示自訂變數的內容
}
5、nginx全域變數
$args : #這個變數等於請求行中的參數,同$query_string
$content_length : #要求標頭中的Content-length欄位。
$content_type : #要求標頭中的Content-Type欄位。
$document_root : #當前請求在root指令中指定的值。
$host : #請求主機頭欄位,否則為伺服器名稱。
$http_user_agent : #用戶端agent資訊
$http_cookie : #用戶端cookie資訊
$limit_rate : #這個變數可以限制串連速率。
$request_method : #用戶端請求的動作,通常為GET或POST。
$remote_addr : #用戶端的IP地址。
$remote_port : #用戶端的連接埠。
$remote_user : #已經經過Auth Basic Module驗證的使用者名稱。
$request_filename : #當前請求的檔案路徑,由root或alias指令與URI請求產生。
$scheme : #HTTP方法(如http,https)。
$server_protocol : #請求使用的協議,通常是HTTP/1.0或HTTP/1.1。
$server_addr : #伺服器位址,在完成一次系統調用後可以確定這個值。
$server_name : #伺服器名稱。
$server_port : #請求到達伺服器的連接埠號碼。
$request_uri : #包含請求參數的原始URI,不包含主機名稱,如:”/foo/bar.php?arg=baz”。
$uri : #不帶請求參數的當前URI,$uri不包含主機名稱,如”/foo/bar.html”。
$document_uri : #與$uri相同