Note: This article was originally published in 2014. Some steps, commands, or software versions may have changed. Check the current NginX documentation for the latest information.

In this step-by-step guide, you’ll learn use nginx as a forward proxy server. Nginx is a high-performance HTTP server and reverse proxy, known for its stability, rich feature set, and low resource consumption.

Prerequisites

Before you begin, make sure you have:

  • A Linux server with Nginx installed
  • Root or sudo access to the server
  • Basic understanding of web server configuration

How to: Use NginX as a Forward Proxy server

Generally people use NginX as a Reverse Proxy server, which is what it was designed for. However, after working with NginX for sometime now, I realized conceptually a proxy server could work both ways, right? The thought is an interesting one but its market might be limited. You could leverage the caching mechanism to provide a faster experience to users or as a method to bypass firewalls potentially. I generally don’t think public proxy servers are safe as it is rather easy to intercept your information but hosting your own addresses that issue. At this point you are probably thinking… why not simply install a system that is truly developed as a forward proxy server like http://www.privoxy.org/? Well, you got me! I am mostly doing this because I already have a WebCaching NginX server I could easily turn into a forward proxy. I really don’t feel like having another piece of software on my stack I need to learn and understand. So if you are in the same boat that you want to have NginX go both ways then read on!

If you have used NginX as a Reverse proxy this is going to be really simple and straight forward. The only difference now is going to be you using an actual public web server as the upstream server. If you haven’t worked with NginX as a proxy server, fear not, it is rather simple once you get the hang of it.

In general people use a proxy server to access sites that their network might be blocking… or if you host a server in a particular country you might get access to content that is not available in your country (think Pandora, Netflix, etc).

I. Add a Server Block to accept connections for the sites you want to forward proxy to:

 

(http://img.zemanta.com/zemified_h.png?x-id=93fb628f-f4c6-4a64-b75b-388268a36bc4)](http://www.zemanta.com/?px “Enhanced by Zemanta”)

Summary

You’ve successfully learned use nginx as a forward proxy server. If you run into any issues, double-check the prerequisites and ensure your NginX environment is properly configured.