Monday, March 19, 2018

mod rewrite - Custom Apache ErrorDocument with proxy balancer & RewriteEngine



I'm running into various problems trying to add custom ErrorDocuments to my server.



I'm using proxy balancer to share the load between two instances of Zope and some simple rewrite rules to map my domain to the local zope instances. I'm pretty sure Zope isn't the problem, but have mentioned it to explain what the balancer redirects to.



I've tried a number of suggestions, but the 'closest' I can get is included below and results in the error:





"Firefox has detected that the server
is redirecting the request for this
address in a way that will never
complete."




Other variations result in:





"The server is temporarily unable to
service your request due to
maintenance downtime or capacity
problems. Please try again later.



Additionally, a 503 Service
Temporarily Unavailable error was
encountered while trying to use an
ErrorDocument to handle the request."





If I include a simple




ErrorDocument 503 Hello




It renders fine.



What am I doing wrong? I'm worried that it may be something to do with the balancer/rewrite getting 'in the way' of the custom errors? Or that my DocumentRoot is incorrectly set?




The rest of this configuration runs fine without the custom errors.




VirtualHost XXX.XXX.XXX.XXX:80>
ServerAdmin webmaster@localhost
ServerName sub.domain.com


BalancerMember http://XXX.XXX.XXX.XXX:81

BalancerMember http://XXX.XXX.XXX.XXX:82


RewriteEngine On
RewriteRule ^(.*)$ balancer://domain_dev$1 [P,L]


Order allow,deny
Allow from all





Listen 81
Listen 82


CustomLog /var/log/apache2/domain-dev-1.log combined
ErrorLog /var/log/apache2/domain-dev-error-1.log


ErrorDocument 503 http://sub.domain.com/custom-errors/customerror.html
Alias /customerrors /var/www/custom-errors/

RewriteEngine On
RewriteRule ^(.*)$ http://localhost:6080/++skin++SandboxSkin/site/++vh++http:sub.domain.com:80/++$1 [P,L]
RewriteLog /var/log/apache2/domain-dev-rewrite-1.log
RewriteLogLevel 0




Order allow,deny
Allow from all





CustomLog /var/log/apache2/domain-dev-2.log combined
ErrorLog /var/log/apache2/domain-dev-error-2.log


RewriteEngine On
RewriteRule ^(.*)$ http://localhost:6081/++skin++SandboxSkin/site/++vh++http:sub.domain.com:80/++$1 [P,L]
RewriteLog /var/log/apache2/domain-dev-rewrite-2.log
RewriteLogLevel 0


Order allow,deny
Allow from all





Answer



Setting LogLevel Debug I found:



[Mon Sep 14 19:26:06 2009] [debug] proxy_util.c(2015): proxy: connected /++skin++SandboxSkin/site/++vh++http:sub.domain.com:80/++/custom-errors/customerror.html to localhost:6080


Which confirmed that the proxy was trying to serve the error from the offline servers location.




Adding:



RewriteCond %{REQUEST_URI} !^/custom-errors/


Stopped the proxy rewriting any redirects with 'custom-errors' directories in the request.



After that, the following simplified ErrorDocument rule worked fine:



DocumentRoot "/var/www"

ErrorDocument 503 "/custom-errors/customerror.html"

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...