本来以为应该挺简单的,先上网搜了一下,发现写的都有点老了,不太敢用,所以还是去官网看了一下:
http://nginx.org/en/linux_packages.html#RHEL-CentOS
![2f13a1ac280541ccdf690aeb8e9f19c9.png](https://img-blog.csdnimg.cn/img_convert/2f13a1ac280541ccdf690aeb8e9f19c9.png)
就三步:
1、装依赖
sudo yum install yum-utils
![f7e9ce9af7b330ab49561f564574bc1e.png](https://img-blog.csdnimg.cn/img_convert/f7e9ce9af7b330ab49561f564574bc1e.png)
2、创建yum仓库源文件
cd /etc/yum.repos.d
vim nginx.repo
# nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
3、安装nginx
sudo yum install nginx
![bad11df39fb65e55496b1463351ee007.png](https://img-blog.csdnimg.cn/img_convert/bad11df39fb65e55496b1463351ee007.png)
OK了,我都不知道为什么很多文章写的这么复杂。
不过要注意就是,安装之后的目录结构并不是在usr/local下面:
安装目录(配置文件:nginx.conf 和 conf.d):/etc/nginx
![0cfdde05cce2588df028d555ceb2ee56.png](https://img-blog.csdnimg.cn/img_convert/0cfdde05cce2588df028d555ceb2ee56.png)
项目静态资源目录:/usr/share/nginx/html
![7f2138c97075b47a9abd423d08ecd3c9.png](https://img-blog.csdnimg.cn/img_convert/7f2138c97075b47a9abd423d08ecd3c9.png)
日志目录:/var/log/nginx
![a30d5fcc7d0ce109f6b0eb797f72d9dd.png](https://img-blog.csdnimg.cn/img_convert/a30d5fcc7d0ce109f6b0eb797f72d9dd.png)
最后是启动和停止的命令:
- systemctl start nginx
- systemctl stop nginx
仅做记录。