How to Use Nginx as a Reverse Proxy – getinpc.info

In addition to Apache, Nginx is the most popular web server. Not only is it a web server, it can also be used as a load balancer or reverse proxy. This tutorial shows you how to use Nginx as a reverse proxy.

What is a reverse proxy?

The proxy server acts as an intermediary between the client and other servers. Sends the resource for retrieval and viewing on the server to which you are connecting. Reverse proxies work the same way, except that roles are reversed. When a server requests information, the reverse proxy holds the request and sends it to the appropriate back-end server. This allows system administrators not only to use servers for multiple applications, but also to ensure smooth traffic flow between clients and servers.

Benefits of reverse proxies [19659004] The use cases for reverse proxies may vary depending on the application.

  • The reverse proxy allows you to run multiple applications on the same server. – If you are running multiple applications on the same server, not all of them are listening to port 80 or 433 at the same time. The reverse proxy allows you to configure the reverse proxy to redirect traffic to individual apps as needed.
  • Load Balancing – If you have multiple servers running the same app, you can distribute using a reverse proxy.
  • Web Application Firewall – You can use a reverse proxy to filter spam IP or protect against DDOS attacks without revealing the application.
  • Easy Logging and Auditing – All incoming traffic is managed by a reverse proxy, making it easier to log and monitor traffic flows.

Configuring Nginx as a Reverse Proxy

Nginx using a reverse proxy uses the parameters proxy_pass in the Nginx configuration file.

Note : This tutorial assumes you have knowledge of Nginx and have already installed and set up Nginx on your server.

In most cases, Ngin x is a front-end server that listens on port 80 (HTTP) or 443 (HTTPS) for incoming requests. There can only be one service listening on port 80 or 443, so the application needs to listen on another port, such as port 8081. The simplest configuration is as follows:

This means that all requests coming in on myapp.com on port 80 will be redirected to port 8081.

Advanced settings

In addition to the proxy_pass directives, there are a few other directives you can use for advanced settings.

proxy_set_header – You can now set to send headers to background apps. For example, see the following configuration:

You can set the application to pass the necessary proxy headers to know the request IP and remote address and output the correct content for the requesting site.

Proxy Timeout – You can now set a timeout value for sending and receiving proxy requests. For example:

proxy_buffers – Nginx temporarily keeps the response from the proxy server and can only send it to the request server after the proxy server has finished responding. For example:

You can disable proxy_buffers if you want to send large file chunks in your app.

Summary

As you can see, Nginx is a possible reverse proxy server. The best thing about it is that the configuration is simple, easy to use and still scalable for complex scenarios. Check the Nginx proxy module documentation or configuration example for details.

Image Credit: Reverse Proxy, Reverse Proxy

Is this article useful?

Leave a Reply

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