Loading...
Loading...
Compare original and translation side by side
/etc/nginx/nginx.confincludewhich nginxnginx -vpgrep nginxps aux | grep nginxss -tlnp | grep <port>netstat -tlnp | grep <port>cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak/etc/nginx/nginx.confincludewhich nginxnginx -vpgrep nginxps aux | grep nginxss -tlnp | grep <port>netstat -tlnp | grep <port>cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak/etc/nginx/nginx.conf/etc/nginx/conf.d//etc/nginx/sites-available//etc/nginx/sites-enabled//etc/nginx/nginx.conf/etc/nginx/conf.d//etc/nginx/sites-available//etc/nginx/sites-enabled/| Setting Type | Location | Reason |
|---|---|---|
| Log format definitions | | Must be defined before use in server blocks |
| Rate limiting zones | | Zones are shared across server blocks |
| Server blocks | | Modular, easy to manage |
| Custom error pages | Server block or location block | Context-specific |
| 设置类型 | 位置 | 原因 |
|---|---|---|
| 日志格式定义 | | 必须在server块引用之前定义 |
| 速率限制区域 | | 区域可在多个server块之间共享 |
| Server块 | | 模块化设计,易于管理 |
| 自定义错误页面 | Server块或location块 | 基于上下文生效 |
limit_req_zone $binary_remote_addr zone=zonename:10m rate=10r/s;limit_req zone=zonename burst=5 nodelay;limit_req_zone $binary_remote_addr zone=zonename:10m rate=10r/s;limit_req zone=zonename burst=5 nodelay;log_format custom_format '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';access_log /var/log/nginx/custom_access.log custom_format;log_format custom_format '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';access_log /var/log/nginx/custom_access.log custom_format;| Environment | Start Command | Reload Command | Stop Command |
|---|---|---|---|
| systemd | | | |
| Direct | | | |
| Docker/Container | | | |
nginx -t| 环境 | 启动命令 | 重载命令 | 停止命令 |
|---|---|---|---|
| systemd | | | |
| 直接运行 | | | |
| Docker/容器 | | | |
nginx -tcurl -s http://localhost:<port>/
curl -s -o /dev/null -w "%{http_code}" http://localhost:<port>/nonexistentcurl -s http://localhost:<port>/
curl -s -o /dev/null -w "%{http_code}" http://localhost:<port>/nonexistentseq 20 | xargs -P 20 -I {} curl -s -o /dev/null -w "%{http_code}\n" http://localhost:<port>/for i in {1..20}; do curl -s http://localhost:<port>/; done # Too slow, sequentialseq 20 | xargs -P 20 -I {} curl -s -o /dev/null -w "%{http_code}\n" http://localhost:<port>/for i in {1..20}; do curl -s http://localhost:<port>/; done # 速度过慢,为顺序请求tail -f /var/log/nginx/access.log
tail -f /var/log/nginx/error.logtail -f /var/log/nginx/access.log
tail -f /var/log/nginx/error.logxargs -Pnginx -tss -tlnpnginxrm -f /etc/nginx/sites-enabled/defaultls -la /etc/nginx/conf.d/xargs -Pnginx -tss -tlnpnginxrm -f /etc/nginx/sites-enabled/defaultls -la /etc/nginx/conf.d/mkdir -prm -fmkdir -prm -fnginx -tnginx -t