原创

CentOS 6.5 使用yum命令方便快捷安装Nginx

        Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,并发能力强。


1、创建一个文件 /etc/yum.repos.d/nginx.repo,并将一下内容复制到文件中:

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


2、编辑并保存/etc/yum.repos.d/nginx.repo文件后,执行yum list | grep nginx 命令查看最新稳定版,如下:

[root@localhost yum.repos.d]# yum list | grep nginx
nginx-filesystem.noarch                   1.0.15-11.el6                 installed
collectd-nginx.x86_64                     4.10.9-1.el6                  epel    
munin-nginx.noarch                        2.0.25-1.el6                  epel    
nginx.x86_64                              1.6.2-1.el6.ngx               nginx   
nginx-debug.x86_64                        1.6.2-1.el6.ngx               nginx   
nginx-debuginfo.x86_64                    1.6.2-1.el6.ngx               nginx   
nginx-nr-agent.noarch                     2.0.0-4.el6.ngx               nginx   
owncloud-nginx.noarch                     6.0.6-1.el6                   epel


3、执行yum -y install nginx安装,信息如下:

[root@localhost yum.repos.d]# yum -y install nginx
Loaded plugins: security
Setting up Install Process
Resolving Dependencies
There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.
--> Running transaction check
---> Package nginx.x86_64 0:1.6.2-1.el6.ngx will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================
 Package                 Arch                     Version                           Repository               Size
==================================================================================================================
Installing:
 nginx                   x86_64                   1.6.2-1.el6.ngx                   nginx                   336 k

Transaction Summary
==================================================================================================================
Install       1 Package(s)

Total download size: 336 k
Installed size: 828 k
Downloading Packages:
nginx-1.6.2-1.el6.ngx.x86_64.rpm                                                           | 336 kB     00:12     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : nginx-1.6.2-1.el6.ngx.x86_64                                                                   1/1 
----------------------------------------------------------------------

Thanks for using nginx!

Please find the official documentation for nginx here:
* http://nginx.org/en/docs/

Commercial subscriptions for nginx are available on:
* http://nginx.com/products/

----------------------------------------------------------------------
  Verifying  : nginx-1.6.2-1.el6.ngx.x86_64                                                                   1/1 

Installed:
  nginx.x86_64 0:1.6.2-1.el6.ngx                                                                                  

Complete!


4、此类安装与源码编译安装Nginx是完全不一样的,执行find / -name *nginx* 和 whereis nginx命令,如下:

[root@localhost /]# find / -name *nginx*
/usr/sbin/nginx
/usr/share/nginx
/etc/nginx
/etc/nginx/nginx.conf
/etc/logrotate.d/nginx
/etc/sysconfig/nginx
/etc/yum.repos.d/nginx.repo
/etc/rc.d/rc4.d/S85nginx
/etc/rc.d/rc5.d/S85nginx
/etc/rc.d/rc6.d/K15nginx
/etc/rc.d/rc0.d/K15nginx
/etc/rc.d/rc1.d/K15nginx
/etc/rc.d/rc3.d/S85nginx
/etc/rc.d/init.d/nginx
/etc/rc.d/rc2.d/S85nginx
/var/lib/yum/yumdb/n/3c706f3b7aab0c74fa1c2b090a71e8d5b28d4927-nginx-1.6.2-1.el6.ngx-x86_64
/var/lib/yum/repos/x86_64/6/nginx
/var/log/nginx
/var/cache/yum/x86_64/6/nginx
/var/cache/yum/x86_64/6/epel/packages/nginx-filesystem-1.0.15-11.el6.noarch.rpm
/var/cache/nginx

[root@localhost /]# whereis nginx
nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx


5、执行service nginx start 命令启动Nginx服务,如下:

[root@localhost nginx]# service nginx start
Starting nginx:                                            [  OK  ]


6、执行service nginx stop 命令停止Nginx服务,如下:

[root@localhost nginx]# service nginx stop
Stopping nginx:                                            [  OK  ]


异常问题:

Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
                                                           [FAILED]

报以上错误说明80端口被占用,更换其他端口即可。

关注下方微信公众号“Java精选”(w_z90110),回复关键字领取资料:如HadoopDubboCAS源码等等,免费领取资料视频和项目。 

涵盖:程序人生、搞笑视频、算法与数据结构、黑客技术与网络安全、前端开发、Java、Python、Redis缓存、Spring源码、各大主流框架、Web开发、大数据技术、Storm、Hadoop、MapReduce、Spark、elasticsearch、单点登录统一认证、分布式框架、集群、安卓开发、iOS开发、C/C++、.NET、Linux、Mysql、Oracle、NoSQL非关系型数据库、运维等。

评论

分享:

支付宝

微信