我的知识记录

腾讯云虚拟主机Web服务器_Nginx 502

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

Apache配置结构:主配置httpd.conf → Include conf.d/*.conf → 虚拟主机VirtualHost → .htaccess(目录级覆盖)。.htaccess需要AllowOverride All才生效,mod_rewrite模块要开启。Apache配置改完systemctl reload httpd,.htaccess改完立即生效不需要重启。

参考(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 ```

安全配置:server_tokens off隐藏版本号、add_header X-Frame-Options SAMEORIGIN防点击劫持、add_header X-Content-Type-Options nosniff、SSL用TLS1.2+、禁止敏感文件访问(location ~* .(sql|bak|log)$ { deny all; })、后台路径IP白名单、限流limit_req。

Nginx错误日志速查:"emerg" 配置语法错(nginx -t看行号)、"alert" 权限问题、"crit" 资源不足、"error" 一般错误(404/403/502)、"warn" 警告。日志级别在error_log指令设置,生产环境用warn或error,调试用debug。

腾讯云虚拟主机Web服务器_Nginx 502

标签:

更新时间:2026-08-26 21:59:01

上一篇:网站安全_网站被黑处理

下一篇:华夏名网虚拟主机不带 www 跳转到带 www返回301_Apache .htaccess与IIS web.config对照