Share on Social Media

In this configuration guide, you will learn, how to setup Nginx Reverse Proxy in CentOS 7 or other Redhat based Linux distros. #centlinux #linux #nginx

What is Nginx? :

Nginx is a free and open-source web server. Nginx can also be used as reverse proxy, load balancer, mail proxy and HTTP cache. Currently, it is the second most widely used web server over the Internet. Also, there are many web servers that are using Nginx as the Reverse Proxy and Load Balancer.

Nginx, pronounced “engine-x,” is a high-performance open-source web server and reverse proxy server software. Originally developed to address the C10k problem, which refers to efficiently handling a large number of simultaneous connections, Nginx has become widely popular for its speed, scalability, and versatility. It efficiently serves static content, manages dynamic content through FastCGI or other modules, and acts as a load balancer to distribute incoming traffic across multiple servers.

One of Nginx’s key strengths lies in its event-driven, asynchronous architecture, allowing it to handle numerous connections simultaneously with low resource consumption. Its modular design supports various add-ons and extensions, making it adaptable for diverse use cases. Nginx is often utilized as a front-end proxy to improve the performance and security of web applications, and it excels in serving as a reverse proxy for distributing incoming requests to backend servers.

In addition to its role as a web server, Nginx is employed as a caching server, SSL/TLS terminator, and as a general-purpose TCP/UDP proxy. Its widespread adoption by high-traffic websites, content delivery networks (CDNs), and as a component in containerized applications underscores its reliability and efficiency in handling modern web infrastructure challenges.

In this article, we will setup Nginx Reverse Proxy in CentOS 7.

System Specification:

In this article, we are using three virtual machines. Two VMs to deploy and run two websites and One VM to configure as the reverse proxy and HTTP load balancer.
IP Address192.168.116.51/24192.168.116.52/24192.168.116.54/24
Operating SystemCentOS 7.6CentOS 7.6CentOS 7.6
Web ServerApacheApacheNginx

We have already configured and as the web servers and hosted a simple and distinct webpage on both servers.


Install Nginx on CentOS 7:

Connect to using ssh.

Nginx can be installed from EPEL (Extra Packages for Enterprise Linux) yum Repository. Therefore, we have to install EPEL yum repository.

# yum install -y epel-release

Let the yum create cache of repositories using following command.

# yum makecache

Install Nginx web server from EPEL yum repository.

# yum install -y nginx

Start and enable nginx.service.

# systemctl start nginx.service
# systemctl enable nginx.service
Created symlink from /etc/systemd/system/ to /usr/lib/systemd/system/nginx.service.

Allow http service in Linux Firewall.

# firewall-cmd --permanent --add-service=http
# firewall-cmd --reload

Browse URL in a client browser.


Nginx Web Server has been installed.

Setup Nginx Reverse Proxy in CentOS 7:

Our Nginx web server is already configured and running at default HTTP port 80.Although, we can configure the same HTTP port as reverse proxy load balancer, but we will keep it clean and add new configurations for the port 8888.

Create a new Nginx configuration file.

# vi /etc/nginx/conf.d/app.conf

Add following directives therein.

upstream appset {

server {
 listen 8888;

 location / {
  proxy_pass http://appset;

Adjust SELinux policy to allow Nginx to run HTTP service on port 8888.

# semanage port -a -t http_port_t -p tcp 8888

Allow service port 8888/tcp in Linux Firewall.

# firewall-cmd --permanent --add-port=8888/tcp
# firewall-cmd --reload

Restart nginx.service.

# systemctl restart nginx.service

Browse URL in a client browser.


Our request has been served by

Refresh webpage again.


Now it forwards, our request to

We have configured a Reverse Proxy and Load Balancer using Nginx Web Server. Here, the configurations are basic and are solely for the demonstration purpose. However, you can amend the same configurations according to your environment to create a relatively advanced Load Balancer.


In this configuration guide, you have learned, how to setup Nginx Reverse Proxy in CentOS 7 or other Redhat based Linux distros.

3 thoughts on “How to setup Nginx Reverse Proxy in CentOS 7”
  1. after installation when I try to access it through web it is not accessible .. after this when i configure upstraem servers ip/names its status is failed..then i remove all of its configuration then its status is running i dont why ?

Leave a Reply

Your email address will not be published. Required fields are marked *