The nginx HTTP module is configured with common instructions

  • 2020-05-07 20:53:17
  • OfStack

What is the function of module?

The HTTP module of Nginx is used to control the HTTP process of Nginx.

2. Configure the directive

1. alias
Meaning: specify the path location USES, similar to root, but does not change the path of the file, only the path of the file system.
Grammar: alias < file-path | directory-path >
Default: N/A
Scope: http.server.location
Example:

location /i/ {
    alias /home/michael/web/i/;
}

Such as request/i/logo png returns/home michael web/i/logo png.
Note:
(1) variables can be used when replacing paths.
(2) alias cannot be used in regular location. If there is such a need, rewrite and root must be used.

2. client_body_in_file_only
Specifies whether to store the body of a user request in a file.
Grammar: client_body_in_file_only < on | off >
Default: off
Scope: http.server.location
Example: client_body_in_file_only on;
Note:
(1) when the instruction is on, the user's request will be stored in a file, but the file will not be deleted after the request ends;
(2) this instruction is usually used during debugging.

3. client_body_buffer_size
Meaning: specifies the maximum value of buffer used by the user request body
Grammar: client_body_buffer_size < size >
Default: two sizes of page, 1 usually 8k or 16k
Scope: http.server.location
Example: client_body_buffer_size 512k;
Note: if the user request body exceeds the size of buffer, all or part of the content is stored in a temporary file.

4. client_body_temp_path
Meaning: sets the directory path to the file that stores the body of the user's request
Grammar: client_body_temp_path < directory path > [level1 | level2 | level3]
Scope: http.server.location
Example: client_body_temp_path /spool/nginx/client_temp 12;

5. client_body_timeout
Meaning: sets the timeout time for the body of the user request.
Grammar: client_body_timeout < time >
Scope: http.server.location
Example: client_body_timeout 120s;
Note: this timeout is set only if the body of the request needs to be read more than once. And if the user sends nothing after this time, nginx returns requests time out 408.

6. client_header_buffer_size
Meaning: sets the size of buffer used by the user request header
Grammar: client_header_buffer_size < size >
Default: 1 k
Scope: http.server
Example: client_header_buffer_size 2k;
Note:
(1) for most requests, 1k is sufficient to satisfy the buffer required by the request header;
(2) buffer1 of 1k is not enough to carry a larger cookie or request header from wap users, so you can use the directive large_client_header_buffers.

7. client_header_timeout
Meaning: sets the timeout time for the user request header.
Grammar: client_header_timeout < time >
Default: 1 m
Scope: http.server.location
Example: client_header_timeout 3m;
Note: this timeout is set only if the request header needs to be read more than once. And if the user sends nothing after this time, nginx returns requests time out 408.

8. client_max_body_size
Meaning: sets the size of the maximum request body that can be received
Grammar: client_max_body_size < size >
Default: 1 m
Scope: http.server.location
Example: client_max_body_size 2m;
Note: the size of the request body is determined by Content-Length in the request header. If it is greater than the set value, the error "Request Entity Too Large" (413) is returned. It is important to note, however, that browser 1 does not specifically display this error.

 


Related articles: