Nginx Ubuntu vs CentOS 常用命令对照表---详解笔记
Nginx Ubuntu vs CentOS 常见对照表
功能 | Ubuntu/Debian 系列 | CentOS/RHEL 系列 |
---|---|---|
安装命令 | sudo apt update && sudo apt install nginx -y | sudo yum install nginx -y 或 sudo dnf install nginx -y |
启动服务 | sudo systemctl start nginx | sudo systemctl start nginx |
停止服务 | sudo systemctl stop nginx | sudo systemctl stop nginx |
重启服务 | sudo systemctl restart nginx | sudo systemctl restart nginx |
查看状态 | sudo systemctl status nginx | sudo systemctl status nginx |
开机自启 | sudo systemctl enable nginx | sudo systemctl enable nginx |
主配置文件 | /etc/nginx/nginx.conf | /etc/nginx/nginx.conf |
虚拟主机配置目录 | /etc/nginx/sites-available/ + /etc/nginx/sites-enabled/ (通过软链接启用) | /etc/nginx/conf.d/ (直接放 .conf 文件) |
默认网页目录 | /var/www/html/ | /usr/share/nginx/html/ |
测试配置是否正确 | sudo nginx -t | sudo nginx -t |
防火墙放行 HTTP/HTTPS | sudo ufw allow 'Nginx Full' | sudo firewall-cmd --add-service=http --permanent && sudo firewall-cmd --reload |
日志文件路径 | 访问日志:/var/log/nginx/access.log 错误日志:/var/log/nginx/error.log | 访问日志:/var/log/nginx/access.log 错误日志:/var/log/nginx/error.log |
重点记住三点差异:
- 安装命令(
apt
vsyum/dnf
) - 站点配置目录(Ubuntu 用
sites-available/
+sites-enabled/
,CentOS 用conf.d/
) - 网页目录(Ubuntu 在
/var/www/html/
,CentOS 在/usr/share/nginx/html/
)