Yet another techie blog by Janne Enberg, aka. Lietu
Nginx reverse proxy cache for multiple sites
If you are hosting a site or multiple sites where performance is more important than that updates are immediately visible, or that the architecture is especially "cool", you might want to think of running Nginx as a reverse proxying cache server.
What this approach provides is easily configurable lightning fast serving of your content.
What you will need
Nginx installed on a server (I'm sure you can find another guide for this)
Write access to Nginx configuration directory
Main web server listening on non-default port (e.g. 8080), or on a different server.
First, locate your nginx configuration folder, it's often /etc/nginx, but you can try: find / -name "nginx.conf"
Inside the configuration folder we will be creating the following structure:
sites-available - Different site configurations
sites-enabled - Currently enabled sites' configurations
include.d - Shared configuration files for sites
conf.d - Additional configuration files
To do this go in your nginx configuration folder, e.g. /etc/nginx and run the following:
It is safe to ignore errors such as "mkdir: cannot create directory `sites-available': File exists".
First step is to configure Nginx to some decent defaults.
Open up your nginx.conf from your nginx configuration folder
Replace the file contents with the following, reading the comments and adjusting accordingly:
Common site configuration
This is configuration that will be shared by all your sites.
Create the file include.d/proxy.conf inside your nginx configuration directory and insert the contents below.
Now for the site-specific configuration. I will be writing the configuration for http://example.com/, but you should of course adjust for your own domain.
Place this in sites-available/example.com in the nginx configuration folder.
You can create as many of these as you need to.
Now to enable a site, you just symlink a file from sites-available/domain.com to sites-enabled/domain.com and reload nginx config. To disable one, you remove the sites-enabled symlink and reload the config.
Assuming your nginx configuration folder is at /etc/nginx, you can run the following to enable domain.com:
Here's a few links to interesting resources on Nginx configuration: