Nginx on CentOS from Nginx repository

CentOS linux has Nginx in it own repository, but unfortunatelly this version is fairly old. Lets go throught adding official Nginx repository and install newer stable version on CentOS with yum. To add new repository from nginx.org run following commands:

cd /tmp
wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm

Now we have new repository and we can install latest version with yum

yum install nginx

Once it is installed, enable the service so it is started automatically after reboot

chkconfig nginx on

We can start the server now but it wont be accessible from outside network so we have to do some configurtation. Edit nginx.conf

vi /etc/nginx/conf.d/default.conf

We need to set the servers IP address and domain name where it will listen

listen       46.229.234.206:80;
server_name  richard.kellnerovci.sk;

Now we can start server (other possible commands: stop, status, restart, reload)

service nginx start

Lets make sure it is running and listening on port 80

netstat -tulpn | grep :80
ps aux | grep nginx

If Nginx welcome site is not accessible in browser most probably firewall is blocking it so lets edit iptables config

vi /etc/sysconfig/iptables

Add following line before the final LOG and DROP lines for the INPUT chain to open port 80:

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

Save and close the file. Now lets restart the firewall and try again...

service iptables restart