Operation and Maintenance
Nginx
Solve the upload file size limit problem by modifying the nginx configuration fileSolve the upload file size limit problem by modifying the nginx configuration file

Problem description:
A new server was installed and nginx was used as a proxy. Suddenly I found that client files larger than 1M could not be uploaded normally, so I modified the nginx configuration.
cd /export/servers/nginx/conf/nginx.conf
The client_max_body_size field is added to the
location / {
root html;
index index.html index.htm;
client_max_body_size 1000m;
}in the server section of this configuration file. No matter how to restart nginx, it will not work. Later, the sub-configuration file was found in the general configuration file:
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
include domains/*; #########################分配置文件路径在此
#include domains/chat.local;
#include domains/chat.erp.com;
#include domains/support.chat.com;
#include douains/chat.com;
server {
listen 80;
server_name localhost;The include domains/* command specifies the path to the sub-configuration file. After finding the sub-configuration file, make modifications in the sub-configuration file. The sub-configuration file configuration is as follows:
server
{
listen 80;
server_name chat.erp.360buy.com;
#access_log /export/servers/nginx/logs/chat.erp.360buy.com;
location / {
proxy_pass http://tomcat;
client_max_body_size 1000m;
}
}Restart with /export/servers/nginx/sbin/nginx -s reload, and the problem of limited upload file size will be solved.
Recommended tutorial: nginx usage tutorial
The above is the detailed content of Solve the upload file size limit problem by modifying the nginx configuration file. For more information, please follow other related articles on the PHP Chinese website!
Nginx and Let's Encrypt SetupJul 24, 2025 am 01:17 AMInstall Nginx and Certbot: Run sudoaptupdate&&sudoaptinstallnginxcertbotpython3-certbot-nginx-y; 2. Configure domain name and Nginx: Make sure DNS points to the server IP and create server-enabled block; 3. Obtain certificate: Execute sudocertbot--nginx-dexample.com-dwww.example.com and follow the prompts; 4. Test automatic renewal: Run sudocertbotrenew-dry-run to verify that the configuration is successful can be achieved free, safe and automated.
How to implement basic authentication (password protection) for a directory?Jul 24, 2025 am 12:28 AMTo encrypt the password protection of the website directory, you can use Basic Authentication, which both Apache and Nginx support. 1. For Apache, first use the htpasswd command to generate a password file, such as htpasswd-c/path/to/.htpasswdadmin to create a user; 2. Then create a .htaccess file in the target directory, configure the AuthType, AuthName, AuthUserFile and Require commands to enable authentication; 3. Pay attention to place the .htpasswd file in the non-site root directory to ensure security. 4. For Nginx, the password text will be created
Nginx Server Blocks ExplainedJul 23, 2025 am 02:35 AMNginxServerBlocks is a configuration hive used by Nginx to decide which website or application to respond to. 1. Each block defines domain name request processing rules through listen, server_name, root and location; 2. Nginx matches server_name according to priority: precise → prefix wild-configuration → suffix wild-configuration → regular → default block; 3. Nginx-t must be used to test the configuration and explicitly set default_server to prevent unmatched domain names from displaying default pages, so as to realize single server hosting multi-sites.
Serving Static Files with NginxJul 23, 2025 am 02:07 AMUse Nginx's alias directive to map the URL path to the static file directory, and set expires1y and Cache-Control headers to improve cache efficiency; 2. For SPA applications, use try_files$uri$uri//index.html to implement front-end routing fallback to ensure that the configuration avoids conflicts after the static path; 3. Disable static file access logs, enable Gzip to compress specific types of files, and prevent executable scripts from running to enhance security; 4. Test configuration and reload services through nginx-t, and use browser developer tools to verify the static resource response header and loading effect.
How to use wildcards or regular expressions in server_name?Jul 23, 2025 am 01:43 AMWhen using server_name in Nginx to match multiple domains or subdomains, it can be achieved through wildcards and regular expressions. 1. When using wildcards, the asterisk can only be used for the beginning or ending, and must be a complete label boundary. For example, .example.com can match first-level subdomains but does not include root domains or multi-level subdomains. If you need to match both root domains and first-level subdomains, it should be written as example.com*.example.com; 2. When using regular expressions, you must start with ~, such as ~^\w .(dev|test)$ can match domain names ending with .dev or .test, and support capture group calls; 3. The matching priority is the exact name>Longest wildcard prefix>Longest wildcard suffix&
Mastering Nginx Location BlocksJul 23, 2025 am 12:26 AMNginx selects location blocks according to priority: = (exact match) is the highest, ^~ (prefix match) is the second, ~ or ~* (regular match) is the lowest, and the normal prefix is the lowest; 2. Common patterns include ^~ optimizing static files, /api/proxy interface, ~ masking hidden files, = quick response root path; 3. Avoid traps: do not abuse regularity, pay attention to the differences in tail slashes, and use try_files reasonably to implement SPA routing; 4. After modification, you must use sudonginx-t to test the configuration and temporarily add /debug path to verify the matching logic. Master the priority order and write efficient and safe Nginx configuration.
How to use Nginx as an ingress controller for Kubernetes?Jul 22, 2025 am 02:54 AMNginx can manage HTTP routing as an IngressController for Kubernetes. 1. The installation can be deployed through Helm or official YAML file, run the kubectlapply command to create the ingress-nginx namespace and related resources, and check the status of the pod to confirm that the installation is successful; 2. Create Ingress rules to define the route, such as forwarding /path to web-app and /api to api-server; 3. Configuring TLS requires preparing a certificate and adding the tls field and secretName; 4. Use annotations to implement custom settings, such as path rewriting, timeout adjustment, etc.; 5. Check the problem and view the controller log
How to prevent hotlinking of images or other assets?Jul 22, 2025 am 02:47 AMPreventing images or other resources from being hot-chained can be achieved through various methods: 1. Use .htaccess to set up anti-theft chains and restrict external access by judging the Referer header; 2. Configure the valid_referers rule in Nginx to prevent illegal requests; 3. Use the Referer whitelist, signature URL and other anti-theft chain functions provided by CDN; 4. Add a watermark or provide thumbnails to the image to reduce the value of theft chain. These methods can be used alone or in combination, effectively reducing bandwidth waste.


Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Atom editor mac version download
The most popular open source editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)






