web analytics

Install nginx webserver in Centos6 server

You can install nginx webserver in Centos6 server with yum. It is simple and easy. Follow the steps given below.

First we need to install the nginx repo

[root@abc ~]# cd /etc/yum.repos.d/

[root@abc yum.repos.d]# wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

[root@abc yum.repos.d]# rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm

Make sure that the repo nginx.repo is listed at /etc/yum.repos.d. Once it is done, you can install nginx using yum

[root@abc yum.repos.d]# yum install nginx

The nginx configuration file is available at /etc/nginx/nginx.conf. You need to update the worker process in it. The worker process can be equal to the number of CPUs in the server.

[root@abc ~]# cat /proc/cpuinfo  | grep processor | wc -l

8

The above output shows there are 8 processors. So edit the nginx conf file and make the changes.

[root@abc ~]# vi /etc/nginx/nginx.conf

worker_processes  8;
Save and exit the file.

nginx works on port 80. So, enable that port in server firewall.

[root@abc ~]# vi /etc/sysconfig/iptables

Add the following line to it, save and exit.

-A INPUT -m state –state NEW -p tcp –dport 80 -j ACCEPT

[root@abc ~]# /etc/rc.d/init.d/iptables restart

 

Now start nginx.

[root@abc ~]# /etc/rc.d/init.d/nginx start

Starting nginx:                                            [  OK  ]

Make sure nginx is listening on port 80

[root@abc ~]# netstat -plan | grep :80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      8731/nginx

Now try accessing http://1.2.3.4 where 1.2.3.4 is your server IP. If you get the following displayed in browser, your nginx is working fine.

 

Now you need to add nginx to startup, so that nginx is started when the server boots.

[root@abc ~]# chkconfig nginx on

[root@abc ~]# chkconfig –list | grep nginx
nginx           0:off   1:off   2:on    3:on    4:on    5:on    6:off

A little help on nginx files

——————————–

Main configuration file – /etc/nginx/nginx.conf

Default Document Root – /usr/share/nginx/html/

Virtual Hosts – /etc/nginx/sites-available/ and  /etc/nginx/sites-enabled/

Error Log – /var/log/nginx/error.log

 

 

One comment to Install nginx webserver in Centos6 server

Leave a reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>