Reverse proxy and cache server using nginx

→ Are you a new visitor? Please visit the page guidance for new visitors ←

Why using Nginx web server?

Some of you will have this question, but others will feel this is the right thing to do. Well either way, I recommend using Nginx as a reverse proxy due to its scalability and performance. Nginx is being used to power up Cloudflare network, so this has been massively tested and used over a very big network. Not only that, but Nginx is lightweight and uses less memory for more requests. In this article I’m going to show you a quick way to use Nginx as a reverse proxy and cache server for static resources.

Setup the reverse proxy server

In my other article I’ve already shown you how to install Nginx, well based on the default settings there you can easily set a reverse proxy by using:

Where 192.168.1.2 is the backend web server which handles the requests.

The virtual host configuration would look similar to the below example:

A bit of explanation:

  • listen — we make nginx listen on port 80 for requests
  • access_log and error_log — I disabled these, you can use them only if you see issues
  • proxy_pass — this is where you will forward requests from your reverse proxy, normally it should be the backend server, but you can use different reverse proxy server here too.
  • proxy_set_header — set the correct http header for our backend servers to know the real IP address of the client browsing our websites
  • proxy_max_temp_file_size — set the maximum amount of size that a file can take in our temp folder

The rest are some default proxy settings I have used which should remain as they are unless you know what you are doing.

That’s basically it for the reverse proxy configuration using nginx.

Page 2 → Reverse cache server using nginx

Pages: 1 2

  • Tomek

    Thank you. This tutorial was very useful.

    • You are welcome, I’m glad it helped!

Request an article ←