1. 程式人生 > 其它 >nginx重新整理——————http請求的11個階段中的precontent階段[十六]

nginx重新整理——————http請求的11個階段中的precontent階段[十六]

前言

簡單介紹一下precontent階段。

正文

介紹一下這個階段的幾個模組。

ngx_http_try_files_module 模組。

syntax : tryfiles file... uri
tryfiles file... code;
default: --
context: server,location

依次試圖訪問多個url對應的檔案(由root 或者alias 指令指定),

當檔案存在時直接返回檔案內容,如果所以檔案都不存在,則按最後一個url結果或者code 返回。

例子:

server {
	server_name www.axm.com;
	error_log  logs/myerror.log  info;
	root html/;
	default_type text/plain;
	
	location /first {
    		try_files /system/maintenance.html
              		$uri $uri/index.html $uri.html
              		@lasturl;
	}

	location @lasturl {
    		return 200 'lasturl!\n';
	}

	location /second {
		try_files $uri $uri/index.html $uri.html =404;
	}

}

例如第一個first,先嚐試獲取/system/maintenance.html,如果不存在然後去獲取/html/first 檔案,

然後去獲取/html/first/index.html,然後/html/first.html,如果全度沒有然後去訪問@lasturl。

這種情況一般情況下是如果維護了,然後就可以把檔案放在某個地方就好。

下面介紹一下拷貝流量。

ngx_http_mirror_module 模組,預設編譯進nginx。

通過--without-http-mirror-module 移除模組。

處理請求時,生成子請求訪問其他服務,對子請求的返回值不做處理。

例如:

下一節content 階段。