我的知识记录

NginxNginx 502_安全加固

Nginx 502时分清是Web服务器本身问题还是后端问题。Nginx 502是后端(PHP-FPM/应用)没响应,504是后端超时,403是Nginx权限或deny规则,404是root路径或伪静态。错误码已经告诉你方向。

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 ```

排查完用nginx -t检测确认。nginx -t返回syntax is ok,systemctl status显示active (running),curl -I返回200,浏览器访问正常。错误日志没有新的error记录。所有location和rewrite规则测试通过。

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

NginxNginx 502_安全加固

标签:

更新时间:2026-08-27 11:50:54

上一篇:网站被挂马流量异常_百度收录异常关键词与SEO恢复

下一篇:新网 Java 主机WebLogic部署SSL证书多域名绑定统一首选域完整教程_快照更新