华为云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示例
# 虚拟主机配置
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、路径是否在网站根目录。虚拟主机用户在面板开启"伪静态"。

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