当访问网站出现 Nginx 相关页面(如默认欢迎页、错误提示等),可能是服务器配置问题或服务异常。以下是逐步排查和解决方案:
Nginx 默认欢迎页(显示 "Welcome to nginx!")
/etc/nginx/sites-enabled/your-site.conf
),确保 root
指向正确的网站目录,并重启 Nginx:sudo nginx -t # 测试配置是否正确
sudo systemctl restart nginx
Nginx 错误页面(如 502 Bad Gateway、404 Not Found)
bash
sudo systemctl status php-fpm # 以 PHP-FPM 为例
fastcgi_pass
或 proxy_pass
)是否正确:
nginx
location ~ \.php$ {
fastcgi_pass unix:/run/php/php-fpm.sock; # 确保路径匹配
}
bash
sudo systemctl restart php-fpm nginx
root
配置错误。root
或 alias
路径:
nginx
server {
root /var/www/html; # 确保目录存在且权限正确
index index.html;
}
bash
sudo chown -R www-data:www-data /var/www/html
bash
sudo chmod -R 755 /var/www/html
index
文件:
nginx
location / {
index index.html index.php;
}
bash
sudo tail -n 50 /var/log/nginx/error.log
bash
sudo systemctl status nginx
bash
sudo systemctl start nginx
sudo systemctl enable nginx
bash
sudo netstat -tulnp | grep :80
bash
sudo ufw allow 80/tcp # Ubuntu
sudo setenforce 0 # 临时禁用 SELinux(不推荐生产环境)
bash
sudo tail -f /var/log/nginx/access.log
bash
sudo tail -f /var/log/nginx/error.log
graph TD
A[访问网站显示Nginx页面] --> B{页面类型?}
B -->|Welcome页| C[检查网站配置]
B -->|502错误| D[检查后端服务]
B -->|404错误| E[检查root路径]
B -->|403错误| F[检查权限]
C --> G[重启Nginx]
D --> G
E --> G
F --> G
G --> H[问题解决]
通过以上步骤,90% 的 Nginx 相关问题可快速定位并解决。如果问题仍存在,请提供具体的错误日志或页面截图进一步分析!