How To Reverse Proxy Multiple WordPress Sites In Nginx ?

Nginx allows you to reverse proxy multiple websites easily within its virtual.conf file. If you have running multiple domains on Apache, it might be a great idea to reverse proxy several of them in order to reduce the load on your server. Especially, if you are hosting multiple WordPress installations, we definitely recommend using Nginx as reverse proxy instead of relying on WordPress caching plugins such as W3 Total Cache, WP Fastest Cache and etc.

Assuming your Apache is running on port 80 and defined virtual hosts in your configuration for several domains, edit your httpd.conf and virtual hosts config file and change all ports from 80 to 82 and restart your apache server. Obviously, this will make all your sites inaccessible for a moment. Now it is time to setup Nginx virtual.conf file to setup multiple reverse proxies.

Nginx Multiple Reverse Proxy Configuration

Assuming you have already installed nginx on your Linux installation and modified nginx.conf before it’s time to modify virtual.conf for reverse proxy setup. If you haven’t installed Nginx yet, you should check the following article first.

Now open your favorite editor and edit file virtual.conf, which is often located under /etc/nginx/conf.d/virtual.conf under Centos installations. The following configuration file contains 2 domains which use WordPress:

Couple Notes On Above Nginx Configuration

  • This configuration uses /home/nginxcache to store all cache files of all domains. You may assign a different cache path for each domain if you want by moving this line under server bracket.
  • The configuration assumes you have a 500.html defined under /var/www/errorpages.
  • The configuration does not cache urls containing query string.
  • The first domain in the configuration is cached for 3 minutes if response codes are 200, 301, 302, while the second domain has 5 minutes. You can override the caching behavior within your WordPress by sending something like this from the functions.php: header(“Cache-Control: public, s-maxage=30”); // cache only 30 seconds.