• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial Comments FAQ Related Articles

How to Configure Nginx as a Reverse Proxy in CentOS

738

To Configure Nginx as a Reverse Proxy in CentOS

Nginx is a webserver or reverse proxy that helps the users to deploy and deliver the sites with high performance, security, etc. It can also create a load balance between multiple back end web servers. This article explains the configuration of Nginx as a Reverse Proxy in CentOS.

Testing Environment

Reverse Proxy:

IP address &ndash 192.168.5.237
Hostname &ndash node1.example.com

Webserver:

IP address &ndash 192.168.5.238
Hostname &ndash node2.example.com

Pre-requisites

Before going to set reverse proxy, setup basic apache web server on the webserver node with any content. And hostname resolution between these machines is must. Inorder to do that configure DNS server or create entry in /etc/hosts file, for example shown below.

Sample Hosts file entry:

192.168.5.237 node1.example.com node1
192.168.5.238 node2.example.com node2


Installation of Nginx

Inorder to install Nginx, we need to add epel repository.

[root@node1 ~]# yum install epel-release -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.fibergrid.in
* extras: mirror.fibergrid.in
* updates: mirror.fibergrid.in
Resolving Dependencies
-->  Running transaction check
--->  Package epel-release.noarch 0:7-6 will be installed
-->  Finished Dependency Resolution
.
.
.
Running transaction
Installing : epel-release-7-6.noarch 1/1
Verifying : epel-release-7-6.noarch 1/1

Installed:
epel-release.noarch 0:7-6

Complete!

Now its time to install Nginx with following command.

[root@node1 ~]# yum install nginx &ndash y
Loading mirror speeds from cached hostfile
* base: mirror.fibergrid.in
* epel: kartolo.sby.datautama.net.id
* extras: mirror.fibergrid.in
* updates: mirror.fibergrid.in
Resolving Dependencies
-->  Running transaction check
--->  Package nginx.x86_64 1:1.10.2-1.el7 will be installed
.
.
.
Dependency Installed:
GeoIP.x86_64 0:1.5.0-9.el7 gperftools-libs.x86_64 0:2.4-7.el7 libunwind.x86_64 2:1.1-5.el7_2.2
nginx-all-modules.noarch 1:1.10.2-1.el7 nginx-filesystem.noarch 1:1.10.2-1.el7 nginx-mod-http-geoip.x86_64 1:1.10.2-1.el7
nginx-mod-http-image-filter.x86_64 1:1.10.2-1.el7 nginx-mod-http-perl.x86_64 1:1.10.2-1.el7 nginx-mod-http-xslt-filter.x86_64 1:1.10.2-1.el7
nginx-mod-mail.x86_64 1:1.10.2-1.el7 nginx-mod-stream.x86_64 1:1.10.2-1.el7

Complete!


To Configure Nginx as Reverse Proxy

Let' s open the Nginx configuration file to configure the Nginx as a reverse proxy.

[root@node1 ~]# vim /etc/nginx/nginx.conf

Disable the Nginx as a webserver in configuration file by commenting the following lines.

#    server {
#        listen       80 default_server 
#        listen       [::]:80 default_server 
#        server_name  _ 
#        root         /usr/share/nginx/html 

        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf 

#        location / {
#        }

#        error_page 404 /404.html 
#            location = /40x.html {
#        }

#        error_page 500 502 503 504 /50x.html 
#            location = /50x.html {
#        }
#    }

Then add the following configuration to enable Nginx as a reverse proxy.

server {
   listen 80 
   server_name node2.example.com 
   access_log off 
   error_log off 
   location / {
      proxy_pass http://192.168.5.238/ 
      proxy_redirect off 
      proxy_set_header Host $host 
      proxy_set_header X-Real-IP $remote_addr 
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for 
      proxy_max_temp_file_size 0 
      client_max_body_size 10m 
      client_body_buffer_size 128k 
      proxy_connect_timeout 90 
      proxy_send_timeout 90 
      proxy_read_timeout 90 
      proxy_buffer_size 4k 
      proxy_buffers 4 32k 
      proxy_busy_buffers_size 64k 
      proxy_temp_file_write_size 64k 
   }
}

Mention the IP address and Hostname for the backend webserver

Restart and enable the nginx service to take effect. Then allow HTTP port on the firewall.

[root@node1 ~]# systemctl start nginx
[root@node1 ~]# systemctl enable nginx
ln -s ' /usr/lib/systemd/system/nginx.service'  ' /etc/systemd/system/multi-user.target.wants/nginx.service' 
[root@node1 ~]# firewall-cmd --permanent --add-service=http
success
[root@node1 ~]# firewall-cmd --reload

Once the above process is completed, call reverse proxy server' s IP address to view the output.

Nginx-as-Reverse-Proxy-IP-address

Tags:
jayce
Author: 

Comments ( 4 )

catpanda
like this:
server {
listen 80;
server_name node2.example.com;
access_log off;
error_log off;
location /nginx {
proxy_pass your_backend_ip;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_max_temp_file_size 0;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}
catpanda
maybe the every single line should endwith semicolon(; )
javedakhtar
i want to install Nginx and update with bash script. Please help me
nambolanpperingeth
server section must be under http {} section
Add a comment

Frequently asked questions ( 5 )

Q

What is the Nginx Web server?

A

NGINX is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. NGINX is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.

Q

Is there any similar web servers like Nginx?

A

Web servers similar to Nginx are
=> Cherokee
=> Lighttpd (Lighty)
=> thttpd

Q

What is a Reverse Proxy?

A

The reverse proxy is to provide Internet users access to a server that is behind a firewall. Reverse proxies can also be used to balance the load among several back-end servers or to provide caching for a slower back-end

Q

Why Nginx is faster than Apache?

A

Nginx can serve more requests per second than Apache on the same hardware.

Q

Is nginx a Load Balancer?

A

Nginx, which is a popular web server software, can be configured as a simple yet powerful load balancer to improve your servers resource availability and efficiency. In a load balancing configuration, nginx acts as a single entry point to a distributed web application working on multiple separate servers.

Related Tutorials in How to Configure Nginx as a Reverse Proxy in CentOS

Related Tutorials in How to Configure Nginx as a Reverse Proxy in CentOS

How To Install AnyDesk on Centos 7
How To Install AnyDesk on Centos 7
Apr 2, 2018
How to install Tiki Wiki CMS Groupware on CentOS 7
How to install Tiki Wiki CMS Groupware on CentOS 7
May 31, 2018
How to install PHP ImageMagick on CentOS 7
How to install PHP ImageMagick on CentOS 7
Nov 4, 2017
How to Upgrade and Downgrade the PHP Versions on CentOS 7.6
How to Upgrade and Downgrade the PHP Versions on CentOS 7.6
Jun 4, 2019
How to install Apache from Source Code on CentOS 7
How to install Apache from Source Code on CentOS 7
Oct 21, 2017
How to enable or disable repositories in CentOS
How to enable or disable repositories in CentOS
Mar 28, 2018
How to install AWStats on CentOS 7
How to install AWStats on CentOS 7
Dec 8, 2017
How to install Apache JMeter in CentOS 7
How to install Apache JMeter in CentOS 7
Mar 24, 2017

Related Forums in How to Configure Nginx as a Reverse Proxy in CentOS

Related Forums in How to Configure Nginx as a Reverse Proxy in CentOS

CentOS
connor class=
How To Completely Remove Apache package On CentOS 7.6
May 14, 2019
Web Server
jacob class=
How to remove httpd completely from server
Apr 7, 2017
CentOS
ceriaimmaculate class=
setfacl : command not found
Jan 3, 2018
CentOS
mason class=
Error getting authority: Error initializing authority: Could not connect: No such file or directory (g-io-error-quark, 1)
Nov 20, 2018
Nginx
gokulravichandran2 class=
Failed to start A high performance web server and a reverse proxy server
Dec 23, 2018
CentOS
landon class=
Command to find SNMP Version
May 28, 2018
CentOS
arjitharon class=
cannot start minio service help
Mar 10, 2018
Apache tomcat
AadrikaAnshu class=
Cannot find ./catalina.sh The file is absent or does not have execute permission This file is needed to run this program
Jun 17, 2019

Related News in How to Configure Nginx as a Reverse Proxy in CentOS

Related News in How to Configure Nginx as a Reverse Proxy in CentOS

PHP7 bugs used by hackers to remotely hijack web servers
PHP7 bugs used by hackers to remotely hijack web servers
Nov 5, 2019
Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Isaac ?
How to run windows application in linux

I need to run the windows application in my Linux machine, instead of installing from yum repo or any other repos. How to do that..??

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.