bingooyong / note

1 stars 1 forks source link

玩转 openresty #42

Open bingooyong opened 3 years ago

bingooyong commented 3 years ago

How to Limit File Upload Size in Nginx

@seehttps://www.tecmint.com/limit-file-upload-size-in-nginx/

In our last article, we’ve explained about limiting user file upload size in Apache. In this article, we will explain how to limit user file upload size in Nginx. Restricting file upload size is useful to prevent some types of denial-of-service (DOS) attacks and many other related issues.

By default, Nginx has a limit of 1MB on file uploads. To set file upload size, you can use the client_max_body_size directive, which is part of Nginx’s ngx_http_core_module module. This directive can be set in the http, server or location context.

It sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. Here’s an example of increasing the limit to 100MB in /etc/nginx/nginx.conf file.

Set in http block which affects all server blocks (virtual hosts).

http {
    ...
    client_max_body_size 100M;
}   

Set in server block, which affects a particular site/app.

server {
    ...
    client_max_body_size 100M;
}

Set in location block, which affects a particular directory (uploads) under a site/app.

location /uploads {
    ...
    client_max_body_size 100M;
} 

Save the file and restart Nginx web server to apply the recent changes using following command.

# systemctl restart nginx       #systemd
# service nginx restart         #sysvinit

Once you have saved the changes and restarted the HTTP server, if the size in a request exceeds the configured value of 100MB, the 413 (Request Entity Too Large) error is returned to the client.

Note: You should keep in mind that sometimes browsers may not correctly display this error. And setting a valua (size) to 0 disables checking of client request body size.

You might also like to read these following articles related to Nginx web server administration.

Reference:[ngx_http_core_module] documentation(https://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size)

That’s all! In this short article, we have explained how to limit user file upload size in Nginx. You can share your thoughts with us via the comment form below.

bingooyong commented 4 months ago

Nginx 最多使用16核CPU

https://plantegg.github.io/2022/10/10/Nginx%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%95/

bingooyong commented 4 months ago

lua-resty-worker-events

lua-resty-worker-events This module provides a way to send events to the other worker processes in an Nginx server. Communication is through a shared memory zone where event data will be stored.

bingooyong commented 4 months ago

LuaJIT-Not-Yet-Implemented

LuaJIT-Not-Yet-Implemented