How To Create Reverse Proxy with Nginx?

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/create-reverse-proxy-nginx/
PINTEREST
PINTEREST
INSTAGRAM

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 poftut.com 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.

  • 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  Linux Ssh Tunneling or Port Forwarding Local and Remote Ports with Examples?

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.

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/create-reverse-proxy-nginx/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)