Loading...
Real Time Concepts

CMS Master Slave Rules

Configuration

Below are a set of Apache rules for ensuring that files uploaded to a load balanced CMS are always put on to the master server, and then correctly displayed in the CMS during the editing phase. These aren’t fully tested, however I have managed to upload and delete the files, and also confirmed that editing a post will still show the image.

These rules work by using RewriteEngine and proxying the requests directly to the master server.

Before you start, you must edit the /etc/hosts file on the slave so that it has the ip address of the master set to the website’s domain name. This removes some issues with drupal and joomla trying to be too clever.

These rules should only be on the slave(s).

RewriteEngine On

####Wordpress

RewriteRule ^/wordpress/wp-admin(.*) http://<HOSTNAME>/wordpress/wp-admin$1 [P]

RewriteCond %{HTTP_REFERER} .*wp-admin.*
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/wordpress/wp-content/(.*) http://<HOSTNAME>/wordpress/wp-content/$1 [P]

#####Drupal

RewriteCond %{QUERY_STRING} .*admin.*
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/drupal/(.*) http://<HOSTNAME>/drupal/$1 [P]

RewriteCond %{HTTP_REFERER} .*add.*
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/drupal/(.*) http://<HOSTNAME>/drupal/$1 [P]

RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{QUERY_STRING} .*file.*
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/drupal/(.*) http://<HOSTNAME>/drupal/$1 [P]

#####Joomla

RewriteRule ^/joomla/administrator(.*) http://<HOSTNAME>/joomla/administrator$1 [P]

RewriteCond %{HTTP_REFERER} .*administrator.*
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/joomla/images/(.*) http://<HOSTNAME>/joomla/images/$1 [P]

RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{QUERY_STRING} .*file\.upload.*
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/joomla/(.*) http://<HOSTNAME>/joomla/$1 [P]

RewriteCond %{QUERY_STRING} .*images.*
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/joomla/(.*) http://<HOSTNAME>/joomla/$1 [P]

RewriteCond %{HTTP_REFERER} .*images.*
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/joomla/(.*) http://<HOSTNAME>/joomla/$1 [P]

RewriteCond %{HTTP_REFERER} .*create-a-post*
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/joomla/(.*) http://<HOSTNAME>/joomla/$1 [P]

RewriteCond %{HTTP_REFERER} .*component*
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/joomla/(.*) http://<HOSTNAME>/joomla/$1 [P]

Leave a Reply

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