在 Debian 上调试 Nginx,一般可以从配置检查、日志查看、进程状态、端口与防火墙、权限问题几个方向入手。下面给你一套实用流程。
systemctl status nginx
如果没启动:
sudo systemctl start nginx
sudo systemctl enable nginx
查看进程:
ps aux | grep nginx
sudo nginx -t
常见错误:
;server_name 写错root 路径不存在location 括号不匹配nginx -T
(会打印所有生效配置,包括 include 的)
sudo tail -f /var/log/nginx/error.log
sudo tail -f /var/log/nginx/access.log
常见错误示例:
Permission denied → 权限问题File not found → root/path 错address already in use → 端口被占用sudo ss -tulnp | grep nginx
或
sudo netstat -tulnp | grep nginx
默认应是:
Debian 常用 ufw:
sudo ufw status
sudo ufw allow 80
sudo ufw allow 443
如果是云服务器,还要检查安全组。
网页目录示例:
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www
SELinux 在 Debian 默认关闭,一般不用管。
server {
listen 80;
server_name example.com;
root /var/www/example;
index index.html;
location / {
try_files $uri $uri/ =404;
}
access_log /var/log/nginx/example.access.log;
error_log /var/log/nginx/example.error.log;
}
改完配置后:
sudo nginx -t
sudo systemctl reload nginx
error_log /var/log/nginx/error.log debug;
然后:
sudo systemctl reload nginx
curl -I http://localhost
curl -v http://localhost
ping example.com
nslookup example.com
nginx -t 输出error.log 报错server 配置我可以帮你精确定位问题。