1,添加Nginx源
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2,查询源是否已添加(也可直接进行第三步安装)
yum search nginx
3,安装Nginx
sudo yum install -y nginx
4,启动Nginx
sudo systemctl start nginx.service
5,设置开机自启
sudo systemctl enable nginx.service
6,测试
访问 http://ip地址(http://XXX.XXX.XXX.XXX) 或 http://域名/ (http://www.XXX.com)
出现 Welcome to nginx! 即成功
--------------------------------------------------------下面是Nginx目录结构和相关命令--------------------------------------------------------
1,执行 whereis nginx 命令,查看Nginx目录:
(1) Nginx配置路径:/etc/nginx/
(2) PID目录:/var/run/nginx.pid
(3) 错误日志:/var/log/nginx/error.log
(4) 访问日志:/var/log/nginx/access.log
(5) 默认站点目录:/usr/share/nginx/html
2,相关命令
netstat ntpl | grep 80 #查看进程信息 ps aux | grep ntinx
sudo nginx #启动
sudo nginx -s stop #停止
sudo nginx -s reload #重启
sudo nginx -c /etc/nginx/nginx.conf #使用指定的配置文件启动 sudo nginx t # 测试配置文件是否有错误
sudo nginx -v#查看版本信息