Install Nginx on CentOS 6

  Uncategorized

Introduction

Nginx is a popular light-weight and high performance web server and commonly used as a proxy. It is quite flexible and a good alternative to Apache.

Requirements

  • CentOS 6 or RHEL 6
  • Local Linux and ProfitBricks firewall ports need to be opened for external requests

Install Nginx

Many distributions include Nginx as part of the default distribution repository. However, this version can become outdated and it is recommended installing from a repository containing the latest version.

One common repository added to CentOS and Red Hat Enterprise Linux (RHEL) servers is the Extra Packages for Enterprise Linux (EPEL). The following command will add the EPEL repository to CentOS 6 or RHEL 6.

sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

Optionally, the Nginx project also maintains a repository containing the latest Nginx build. To add the Nginx repository to CentOS 6 and RHEL 6.

sudo rpm -Uvh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

Note: The above mentioned repositories are also available for the 32-bit (i386/i686) version of Nginx. However, it is highly recommend 64-bit versions be used for production server deployments.

Nginx can now be installed using yum.

sudo yum -y install nginx

Start Nginx

Once Nginx has been installed, the service should be set to start on system boot.

sudo chkconfig nginx on

Now Nginx is ready to start.

sudo /etc/init.d/nginx start

You can verify the process has been started using curl to perform an HTTP request.

curl -i http://localhost/

CentOS 6 has a local firewall enabled by default. Proper TCP ports, such as HTTP port 80 and HTTPS port 443, may need to be opened to allow external requests.

sudo iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
sudo service iptables save

Ports will also need to be opened when using the ProfitBricks firewall.

Views: 0

LEAVE A COMMENT

What is the capital of Egypt? ( Cairo )