CentOS7.0安装Nginx

时间:2023-03-10 06:34:01
CentOS7.0安装Nginx

安装Nginx

yum install nginx

正常情况下必定是:

已加载插件:fastestmirror, langpacks
base | 3.6 kB ::
docker-main | 2.9 kB ::
extras | 3.4 kB ::
updates | 3.4 kB ::
(/): extras//x86_64/primary_db | kB ::
(/): updates//x86_64/primary_db | 2.9 MB ::
Loading mirror speeds from cached hostfile
* base: mirrors..com
* extras: mirrors..com
* updates: mirrors..com
没有可用软件包 nginx。
错误:无须任何处理

遂百度查找,CentOS7系统库中默认是没有Nginx的rpm包的,所以我们自己需要先更新下rpm依赖库。。。

#rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

还是去Nginx官网看了下官方的说法,点击这里(Install|NGINX)。

a、先创建一个yum的一个repository文件:/etc/yum.repos.d/nginx.repo;

b、然后将下面配置黏贴进文件后保存。

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=
enabled=

接下来基本上就顺了。

()安装Nginx

#yum install nginx

()启动Nginx

#service nginx start

或

#systemctl start nginx.service

测试一下是否正常。

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>