使用官方源安装nginx
基于服务器:CentOS
1、配置官方源
vi /etc/yum.repos.d/nginx.repo
输入如下内容(参考https://nginx.org/en/linux_packages.html)
[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
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
2、清除epel源的影响(如果存在epel源则注释掉,没有请忽略)
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak
3、yum重新生成缓存
yum clean all
yum makecache
4、yum安装nginx
yum install -y nginx
5、启动nginx
systemctl start nginx
6、查按nginx相关文件
[root@localhost ~]# rpm -qc nginx #查询nginx配置文件
/etc/logrotate.d/nginx
/etc/nginx/conf.d/default.conf
/etc/nginx/fastcgi_params
/etc/nginx/mime.types
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
7、访问测试,输出”Welcome to nginx!“则说明部署OK
[root@localhost ~]# curl http://127.0.0.1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>