我的知识记录

华为云ECSNginx端口被占_location与rewrite

Nginx端口被占的排查流程:配置语法检测 → 服务状态(systemctl status)→ 错误日志(error.log)→ 端口监听(netstat)→ 权限和路径 → 后端服务状态。按流程走,Nginx/Apache问题10分钟内能定位。

Nginx配置结构:main(全局)→ http(HTTP全局)→ server(虚拟主机)→ location(URL匹配)。每个块用花括号包裹,指令以分号结尾。include可以引入子配置。nginx -t检测语法,nginx -s reload重载。配置文件在 /etc/nginx/nginx.conf或宝塔的 /www/server/panel/vhost/nginx/。

参考(Apache配置与排查): ``` # 语法检测 apachectl configtest httpd -t

# 重载与重启 systemctl reload httpd systemctl restart httpd

# 查看模块 httpd -M | grep rewrite httpd -M | grep ssl

# 错误日志 tail -50 /var/log/httpd/error_log tail -50 /var/log/apache2/error.log

# .htaccess示例 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]

# 虚拟主机配置 ServerName 域名 DocumentRoot /var/www/域名 AllowOverride All Require all granted ErrorLog logs/域名-error_log CustomLog logs/域名-access_log common ```

Nginx性能优化:worker_processes auto(和CPU核数一致)、worker_connections 10240、keepalive_timeout 65、gzip on、sendfile on、tcp_nopush on、open_file_cache缓存文件描述符、静态资源expires 30d。优化后并发连接数提升5-10倍,高并发场景必备。

Apache .htaccess不生效:检查httpd.conf里Directory段的AllowOverride是否All(None时 .htaccess完全忽略)、mod_rewrite是否开启(httpd -M | grep rewrite)、.htaccess文件权限644、路径是否在网站根目录。虚拟主机用户在面板开启"伪静态"。

华为云ECSNginx端口被占_location与rewrite

标签:

更新时间:2026-09-01 13:09:53

上一篇:网站伪静态配置错误导致502_新手也能操作_完整排查流程

下一篇:网站RabbitMQ连接被拒绝解决方法修复教程