Centos yum安装nginx

  • A+
所属分类:Nginx

 

1.查看系统是否有可用yum源,如有可直接使用yum install 安装

# yum list | grep nginx

2.新增nginx yum源

vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

此处配置的是centos7的yum源,如需要centos6 yum源,直接把7改成6就可以了。同样道理如果在rhel上安装,直接把centos改成rhel就可以了。

http://nginx.org/packages/centos/6/$basearch/

http://nginx.org/packages/rhel/7/

再次查看yum源,如显示以下界面说明yum源配置成功

[root@localhost ~]# yum list | grep nginx
 nginx.x86_64 1.10.1-1.el6.ngx nginx
 nginx-debug.x86_64 1.8.0-1.el6.ngx nginx
 nginx-debuginfo.x86_64 1.10.1-1.el6.ngx nginx
 nginx-module-geoip.x86_64 1.10.1-1.el6.ngx nginx
 nginx-module-image-filter.x86_64 1.10.1-1.el6.ngx nginx
 nginx-module-njs.x86_64 1.10.1.0.0.20160414.1c50334fbea6-1.el6.ngx
 nginx
 nginx-module-perl.x86_64 1.10.1-1.el6.ngx nginx
 nginx-module-xslt.x86_64 1.10.1-1.el6.ngx nginx
 nginx-nr-agent.noarch 2.0.0-10.el6.ngx nginx
 nginx16.x86_64 1.6.3-1.w6 webtatic
 nginx18.x86_64 1.8.1-1.w6 webtatic
 pcp-pmda-nginx.x86_64 3.10.9-6.el6 base

3.安装nginx

[root@localhost ~]# yum install -y nginx

4.启动nginx服务

Centos 6

[root@localhost ~]# service nginx start

Centos 7

[root@localhost ~]# systemctl start nginx.service

5.添加防火墙规则,如不生效可重启以下防火墙

Centos 6

[root@localhost ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT

Centos7

[root@localhost ~]# firewall-cmd  --zone=public  --add-port=80/tcp  --permanent

 

在浏览器输入ip地址,出现以下界面说明安装成功。

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: