nginx HTTP模組配置常用指令_nginx

來源:互聯網
上載者:User

一、HTTP模組的作用是什嗎?

Nginx的HTTP模組用於控制Nginx的HTTP進程。

二、配置指令

1. alias
含義:指定location使用的路徑,與root類似,但不改變檔案的跟路徑,僅適用檔案系統的路徑。
文法:alias <file-path | directory-path>
預設:N/A
範圍:http.server.location
樣本:

複製代碼 代碼如下:
location /i/ {
    alias /home/michael/web/i/;
}

如請求 /i/logo.png 則返回 /home/michael/web/i/logo.png。
注意:
(1)替換路徑時,可以使用變數。
(2)alias無法在正則的location中使用。如果有這種需求,則必須使用rewrite和root。

2. client_body_in_file_only
含義:指定是否將使用者請求體儲存到一個檔案裡。
文法:client_body_in_file_only <on | off>
預設:off
範圍:http.server.location
樣本:client_body_in_file_only on;
注意:
(1)該指令為on時,使用者的請求體會被儲存到一個檔案中,但是請求結束後,該檔案也不會被刪除;
(2)該指令一般在調試的時候使用。

3. client_body_buffer_size
含義:指定使用者請求體所使用的buffer的最大值
文法:client_body_buffer_size <size>
預設:兩個page的大小,一般為8k或16k
範圍:http.server.location
樣本:client_body_buffer_size 512k;
注意:如果使用者請求體超過了buffer的大小,則將全部內容或部分內容儲存到一個臨時檔案中。

4. client_body_temp_path
含義:設定儲存使用者請求體的檔案的目錄路徑
文法:client_body_temp_path <directory path> [level1 | level2 | level3]
範圍:http.server.location
樣本:client_body_temp_path /spool/nginx/client_temp 1 2;

5. client_body_timeout
含義:設定使用者請求體的逾時時間。
文法:client_body_timeout <time>
範圍:http.server.location
樣本:client_body_timeout 120s;
注意:只有請求體需要被1次以上讀取時,該逾時時間才會被設定。且如果這個時間後使用者什麼都沒發,nginx會返回requests time out 408.

6. client_header_buffer_size
含義:設定使用者要求標頭所使用的buffer大小
文法:client_header_buffer_size <size>
預設:1k
範圍:http.server
樣本:client_header_buffer_size 2k;
注意:
(1)對絕大多數請求來說,1k足以滿足要求標頭所需的buffer;
(2)對於攜帶有較大cookie或來自於wap使用者的要求標頭來說,1k的buffer一般不夠,這時可以使用指令large_client_header_buffers。

7. client_header_timeout
含義:設定使用者要求標頭的逾時時間。
文法:client_header_timeout <time>
預設:1m
範圍:http.server.location
樣本:client_header_timeout 3m;
注意:只有要求標頭需要被1次以上讀取時,該逾時時間才會被設定。且如果這個時間後使用者什麼都沒發,nginx會返回requests time out 408.

8. client_max_body_size
含義:設定所能接收的最大請求體的大小
文法:client_max_body_size <size>
預設:1m
範圍:http.server.location
樣本:client_max_body_size 2m;
注意:根據要求標頭中的Content-Length來判斷請求體大小是否允許。如果大於設定值,則返回“ Request Entity Too Large”(413)錯誤。不過要注意的是,瀏覽器一般並不對這個錯誤進行特殊顯示。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.