我的知识记录

虚拟主机Nginx 404_修复实操

中资源虚拟主机做Nginx 404,宝塔面板用户在面板"网站"里改配置,面板自动检测语法。手动改 /www/server/panel/vhost/nginx/ 下的配置后,必须nginx -t通过再reload,否则整站挂。

反向代理配置:Nginx location / { proxy_pass http://后端IP:端口; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }。后端没启动或端口不通会502,后端处理慢会504。proxy_read_timeout增大超时。

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

fastcgi参数错是Nginx 404的常见原因。配置语法错看nginx -t报错行修正;端口被占用改listen端口或停占用进程;进程未启动systemctl start;权限不足chown/chmod;模块缺失安装对应模块;代理后端未响应启动后端服务;上传大小超限改client_max_body_size;超时太短改proxy_read_timeout/fastcgi_read_timeout;location匹配错误调整匹配顺序。

Nginx与Apache区别:Nginx事件驱动异步非阻塞,高并发性能好,配置简洁,不支持 .htaccess;Apache进程/线程驱动,稳定,支持 .htaccess和丰富模块,高并发内存占用大。静态资源和高并发选Nginx,需要 .htaccess和复杂模块选Apache,也可以Nginx反代Apache。

虚拟主机Nginx 404_修复实操

标签:

更新时间:2026-09-03 14:51:59

上一篇:35互联虚拟主机屏蔽IP访问_屏蔽爬虫 IP与白名单配合

下一篇:IIS 500_WordPress插件冲突排查