How To Create Reverse Proxy with Nginx? – POFTUT

How To Create Reverse Proxy with Nginx?

Nginx is very popular web server software. It has some advantages over Apache. Some developers and system administrators use Nginx with Apache to get more from advantages. Nginx Reverse proxy is very popular because of the speed provided by Nginx with files and directories by using threads. In this tutorial we will look how to configure a reverse proxy with Nginx.

Install Nginx For Ubuntu, Debian, Kali, Mint

We will install nginx package for Ubuntu ,Debian, Kali and Mint with the following command.

Install Nginx For Ubuntu, Debian, Kali, Mint

Install Nginx For Ubuntu, Debian, Kali, Mint

Install Nginx For Fedora, CentOS, RHEL

For Fedora, CentOS and RHEL installation please execute following yum command.

Create Site Configuration

As we know every site will have a configuration in nginx configuration directory. In most cases each site configuration will hold in a separated file with named with related site name. We will create a site configuration file named with the following lines. This configuration file will be located at

Create Location

Now we will create a Location directive which will be use to add reverse proxy configuration. The location will set the path where requests will be forwarded to the web server. We will create a location which will cover all site.  We will also add some trivial directive to the location

Add Proxy Configuration To The Location

Now we will add configuration options. We will also provide some proxy related information.

We will use proxy_set_header to set header to the HTTP request forwarded to the web server.

echo '
  • proxy_pass is the main configuration where we set the web server protocol, address and port.
  • Host will provide the host information provided by web client
  • X-Forwarded-For will provided the web server we want to forward.
  • X-Forwarded-Proto will provide protocol like http or https used by web client.

Test Configuration

We have changed a lot of configuration in the nginx. So we are human an made mistakes. We should check the new configuration syntax with the configtest command provided by nginx.

Enable Site Configuration

Now we will enable our site by adding a soft link to the /etc/nginx/sites-enabled with the following command.

LEARN MORE  How To Install and Configure Squid Web Proxy Server On Linux?

Restart Nginx

In order to make reverse proxy configuration enabled we should restart the nginx web server to reread the new configuration and make it effective.

Leave a Reply

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