CentOS 6.4 Tutorials

Install Nginx CentOS 6.4 (reverse proxy)

Nginx (pronounced “engine x”) is a free, open-source, high-performance HTTP server. Nginx is known for its stability, rich feature set, simple configuration, and low resource consumption. This tutorial will guide you through setting up Nginx as a reverse proxy in front of a Apache back-end.

The assumption for installing Nginx on CentOS 6.4 is that you are running as root and have a basic understanding of the software required but if you follow this tutorial you should be able to complete the task successfully.

Install Yum Priorities

For a brief overview on and how to configure Yum Priorities you can follow the instructions outlined in our Install YUM Priorities on CentOS tutorial.

# yum install yum-priorities

Installing Nginx on CentOS 6.4 x86_64

Install the EPEL x86_64 YUM Repository

# rpm -Uvh

Install the IUS x86_64 YUM Repository

# rpm -Uvh

Install Nginx (and Apache if you haven’t already)

# yum install nginx
# yum install httpd

Configure Nginx

# vim /etc/nginx/conf.d/how2centos.conf 
## Apache backend for ##
upstream apachebackend  {
    server; #apachebackend

## Start ##
server {
    listen       80 default;
    access_log  /var/log/nginx/  main;
    error_log  /var/log/nginx/;
    root   /usr/share/nginx/html;
    index  index.html index.htm index.php;

## send request back to apachebackend ##
    location / {
        proxy_pass  http://apachebackend;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_redirect off;
        proxy_buffering on;
        proxy_buffers 12 12k;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $remote_addr;
## End ##

Configure Apache

Edit the httpd.conf file so that Apache listens on port 8080 otherwise you’ll have a conflict with Nginx

# vim /etc/httpd/conf/httpd.conf
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, in addition to the default. See also the <VirtualHost>
# directive.
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses (
#Listen 80
Listen 8080

Add Apache and Nginx to the system startup

# chkconfig httpd on
# chkconfig nginx on

Restart Apache and Nginx

# service httpd restart
# service nginx restart

By George

Technical Samurai specializing in open source IT Automation and Cloud Infrastructure.