How to Yum Install Nginx on CentOS

Installing nginx on Ubuntu is straightforward — just run apt-get install nginx.

However, today I set up CentOS 6.2 and found that yum install nginx doesn’t work directly. You need to configure the repository first. Here’s the complete installation process, which is also quite simple:

1. For CentOS 6, first run:
rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
2. Check the nginx info in yum

 

# yum info nginx

 

Loaded plugins: fastestmirror
……

 

3. Install and start nginx
[root@server ~]# yum install nginx
[root@server ~]# service nginx start
Starting nginx:                                            [  OK  ]

4. Then open your browser and enter http://192.168.0.101/ to test. If you see

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.

 Congratulations, you’ve done it!

If you cannot connect to nginx, there could be many reasons, but first check:
1. Whether the nginx service is actually running;
2. Whether the Linux server firewall is enabled

If you’re unable to install, refer to the following:

1. To add the nginx yum repository, create a file /etc/yum.repos.d/nginx.repo and paste the following content into it: 
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
2. After editing and saving the /etc/yum.repos.d/nginx.repo file, run the following command in the terminal: 
[root@localhost ~]# yum list | grep nginx
nginx.i386                               1.4.7-1.el6.ngx               @nginx   
nginx-debug.i386                         1.4.7-1.el6.ngx               nginx
You’ll see it’s the latest stable version 
Then simply run 
yum -y install nginx
to install it 
3. This installation method is completely different from compiling Nginx from source. After installation, run the following command 
[root@localhost ~]# find / -name *nginx*
/etc/nginx/nginx.conf
[root@localhost ~]# whereis nginx
nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx
You’ll find the main files are installed under /etc/nginx 
Next, to start the Nginx service, you can run 
[root@localhost ~]# service nginx start
Starting nginx:                                           [ OK ]
Startup successful. 
 
4. Set to start automatically on boot 
Tested on CentOS 6.5, no manual configuration is needed 
chkconfig nginx on 
It can start automatically on boot by itself 

Leave a Comment

Your email address will not be published.