1.安装Nginx
sudo yum install nginx
2.启动、停止、重启Nginx服务
sudo systemctl start nginx # 启动Nginx
sudo systemctl stop nginx # 停止Nginx
sudo systemctl restart nginx # 重启Nginx
sudo systemctl enable nginx # 设置Nginx开机自启
sudo systemctl disable nginx # 禁止Nginx开机自启
3.检查Nginx配置文件语法错误
sudo nginx -t
4.在Nginx配置文件中添加或修改一个虚拟主机
sudo nano /etc/nginx/conf.d/example.conf
5.在打开的文件中输入您的虚拟主机配置,并保存退出
server {
listen 80;
server_name example.com;
location / {
root /var/www/html;
index index.html;
}
}
6.检查Nginx配置文件更改并重新加载配置
sudo nginx -t # 检查配置文件语法错误
sudo systemctl reload nginx # 重新加载Nginx配置
7.查看Nginx服务状态
sudo systemctl status nginx
8.查看Nginx访问日志
sudo tail -f /var/log/nginx/access.log
9.查看Nginx存放路径
whereis nginx
10.查看Nginx进程
ps -ef|grep nginx