Debian 上 Nginx 日志报错的原因有很多,下面我按常见场景 + 对应日志表现 + 解决办法给你梳理一下,你可以对照自己的报错内容来判断。
日志位置
/var/log/nginx/error.log
典型报错
bind() to 0.0.0.0:80 failed (98: Address already in use)
原因
解决
sudo netstat -tunlp | grep :80
sudo systemctl stop apache2
或修改 Nginx 监听端口:
listen 8080;
典型报错
nginx: [emerg] unknown directive "server_"
nginx: [emerg] duplicate location "/"
检查配置
sudo nginx -t
解决
/etc/nginx/nginx.conf 或 /etc/nginx/sites-enabled/*典型报错
Permission denied
open() "/var/www/html/index.html" failed
原因
解决
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
典型报错
connect() to unix:/run/php/php8.2-fpm.sock failed (2: No such file or directory)
原因
解决
sudo apt install php-fpm
sudo systemctl start php8.2-fpm
确认:
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
典型报错
SSL_CTX_use_certificate_chain_file failed
cannot load certificate
原因
解决
sudo nginx -t
ls -l /etc/ssl/certs/xxx.pem
访问日志
/var/log/nginx/access.log
表现
# 看错误日志
sudo tail -n 50 /var/log/nginx/error.log
# 检查配置
sudo nginx -t
# 查看服务状态
systemctl status nginx
# 重新加载
sudo systemctl reload nginx
你可以把 具体的报错内容(复制 error.log 中的几行)发给我,例如:
2026/01/15 10:22:01 [emerg] 1234#1234: ...
我可以直接告诉你是哪一行配置、怎么改。