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]# 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
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
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://220.127.116.11 where 18.104.22.168 is your server IP. If you get the following displayed in browser, your nginx is working fine.
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.
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