Linux 下 Nginx 启动失败是非常常见的问题,原因很多。下面按最常见 → 次常见给你一个排查清单,基本可以覆盖 90% 的情况。
sudo journalctl -xe
# 或
sudo systemctl status nginx
# 或
sudo nginx -t
重点关注:
sudo nginx -t
常见报错:
unknown directiveunexpected "}"duplicate location✅ 解决:
/etc/nginx/nginx.conf 或 conf.d/*.confsudo nginx -t
sudo systemctl restart nginx
sudo netstat -tunlp | grep ':80'
sudo lsof -i:80
可能是:
✅ 解决:
报错示例:
Permission denied
常见原因:
/root✅ 解决:
sudo chown -R www-data:www-data /your/webdir
sudo chmod -R 755 /your/webdir
(CentOS 用户组可能是 nginx)
getenforce
如果是 Enforcing:
sudo setsebool -P httpd_can_network_connect 1
sudo restorecon -Rv /var/www
sudo ufw status
sudo firewall-cmd --list-all
✅ 开放端口:
sudo ufw allow 80,443/tcp
SSL_CTX_use_certificate_chain_file failed
✅ 检查:
free -h
ulimit -n
sudo nginx -t
sudo systemctl status nginx
sudo journalctl -xe
你可以直接把 报错信息贴出来(尤其是 nginx -t 或 systemctl status nginx 的输出),我可以逐行帮你分析具体原因。