Nginx Apache_Apache虚拟主机配置配置
Apache虚拟主机配置的排查流程:配置语法检测 → 服务状态(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示例
# 虚拟主机配置
安全配置: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。
Apache .htaccess不生效:检查httpd.conf里Directory段的AllowOverride是否All(None时 .htaccess完全忽略)、mod_rewrite是否开启(httpd -M | grep rewrite)、.htaccess文件权限644、路径是否在网站根目录。虚拟主机用户在面板开启"伪静态"。

更新时间:2026-09-01 16:15:12
上一篇:商务中国虚拟主机域名不能访问_域名解析到127.0.0.1解决