Apache Error Document is not working - virtualhost

I am running the apache2 webserver in the linux environment.I want to redirect the users to customized error pages.So have created the error pages & created the symbolic link in the htdocs also like this. static-files -> /app/static-files.
And in the httpd.conf file I have created the virtual host definition and included the error pages also like below:
NameVirtualHost m.mydomain.com:80
<VirtualHost m.mydomain.com:80>
DocumentRoot "/app/httpd-2.2.15/htdocs"
ServerName m.mydomain.com:80
<Directory "/static-files/html/error_pages">
Options FollowSymLinks
Order allow,deny
Allow from all
</Directory>
ErrorLog /app/httpd-2.2.15/logs/error_my_log
ErrorDocument 400 /static-files/html/error_pages/error_400.html
ErrorDocument 401 /static-files/html/error_pages/error_401.html
ErrorDocument 403 /static-files/html/error_pages/error_403.html
ErrorDocument 404 /static-files/html/error_pages/error_404.html
ErrorDocument 408 /static-files/html/error_pages/error_408.html
ErrorDocument 500 /static-files/html/error_pages/error_500.html
ErrorDocument 501 /static-files/html/error_pages/error_501.html
ErrorDocument 502 /static-files/html/error_pages/error_502.html
ErrorDocument 503 /static-files/html/error_pages/error_503.html
ErrorDocument 504 /static-files/html/error_pages/error_504.html
</VirtualHost>
When my app server is down,its not redirecting me to 503 customized error page.I am getting the server specific error page only.But if i put this ErrorDocument out of the virtual host definition its redirecting me to the customized error page. I am striking my head for 3 days.But not able to find the reason.I tried in all browsers.Anybody can help me ?

As you defined DocumentRoot to be "/app/httpd-2.2.15/htdocs", the error pages should be in this directory. Are you sure that the error pages are in this directory?

I'm not 100% sure but when you have an app server running behind Apache and when it is down you have a 404 not found.
It's not a 503 answer. 503 occurs when there is fault on the server (either Apache of the App server) such as load or anything that could happen following a miss configuration.

Related

Apache htaccess ErrorDocument

When I include this if statements in my htaccess file, apache throws Internal Server Error 500:
ErrorDocument 500 /custom_50x.html
ErrorDocument 502 /custom_50x.html
ErrorDocument 503 /custom_50x.html
ErrorDocument 504 /custom_50x.html
<Files "custom_404.html">
<If "-z %{ENV:REDIRECT_STATUS}">
RedirectMatch 404 ^/custom_404.html$
</If>
</Files>
<Files "custom_50x.html">
<If "-z %{ENV:REDIRECT_STATUS}">
RedirectMatch 404 ^/custom_50x.html$
</If>
</Files>
What could be the reason?
The other problem with Apache is that even if a 404 webpage is added to ErrorDocument 404 directive, the status code which the server sends is 200 instead of 404.
The ErrorDocument 50* directives are not working also. Although I have set custom error pages for them, Apache still shows the default errors.

Drupal error on bottom : Not Found The requested URL / was not found on this server

My website works but i have this error on bottom.
Not Found
The requested URL / was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at Port 80
this is my vhost configuration
<VirtualHost *:80>
ServerAdmin admin#xxxx.com
ServerName xxx.net
ServerAlias www.xxxx.net
DocumentRoot /var/www/xxxx.net/
<Directory /var/www/xxxx.net/>
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
ServerSignature Off
ErrorDocument 404 /var/www/xxxx.net/404.html
</VirtualHost>
My 404 page exist at this location /var/www/xxxx.net/404.html
Thx for you help !!!!
This may be malware code trying to load content from another host. I recommend to check your website.

Url rewrite is not working in some cases with XAMPP in Windows 7

I have a PHP website hosted at localhost on my Windows 7 PC, running XAMPP 1.8.2.
And I have rewrite rules as below:
Options -Indexes +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?rt=$1 [QSA,L]
</IfModule>
To rewrite the URL so it will always go into something like: http://mysite.com/index.php?rt=[controller]/[action]/[params]
It works prefect until I found it failed when processing url like: http://mysite.com/error/xxx. It returns a 404 status other than goes to http://mysite.com/index.php?rt=error/xxx. (I do NOT have an sub directory call error/ under my website root folder)
I carefully checked my PHP code and I am sure it is not the cause, and I upload my website to a remote server and everything is fine. So I am pretty sure something is not properly configured in my XAMPP (Apache), that makes the /error/xxx request was treated differently.
Also I found visiting http://mysite.com/error/ gives me 403 but http://mysite.com/[something_else]/ is fine.
Just in case, I paste my vhost.conf here as well:
<VirtualHost *:80>
DocumentRoot "/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "E:\htdocs\mysite.dev"
ServerName mysite.dev
</VirtualHost>
And related httpd.conf:
<Directory "E:\htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
Any help is appreciated!
Finally figure it out after wasting another hour on it!
There is configuration file called httpd-multilang-errordoc.conf under /xampp/apache/conf/extra, and inside it's something like this:
<IfModule alias_module>
<IfModule include_module>
<IfModule negotiation_module>
Alias /error/ "C:/xampp/apache/error/"
<Directory "C:/xampp/apache/error">
AllowOverride None
Options IncludesNoExec
AddOutputFilter Includes html
AddHandler type-map var
Require all granted
LanguagePriority en cs de es fr it ja ko nl pl pt-br ro sv tr
ForceLanguagePriority Prefer Fallback
</Directory>
ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
ErrorDocument 410 /error/HTTP_GONE.html.var
ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var
ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var
</IfModule>
</IfModule>
</IfModule>
The line Alias /error/ "C:/xampp/apache/error/" handles all the request matches domainname.com/error/ and rewrite it to C:/xampp/apache/error/.
Simply commenting out the line solves my problem. Not sure what it does but make things done.
From your last comment it sounds like Apache isn't even correctly configured to the path with your site!
You need to edit the Xampp\apache\conf\httpd.conf file.
First make a BACKUP copy of it.
Edit the line that starts with...
DocumentRoot "
..if it is a Windows machine and it uses / instead of \ retain those.
Then you need to edit the line that starts with...
<Directory "
Be aware that there is also a CGI version of this.
If you have correctly edited the file save and then restart Apache. Changes will NOT take effect until you restart Apache.

How to Create A Custom Apache 503 Error Page

I created an HTML document that will display that the server is not ready yet, and then redirect to another page. I want this to be the 503 error page.
What file do I need to edit in Apache to get this custom HTML to be my new 503 error page? I have tried following the instructions on multiple websites, but it still points to the original Apache one.
This is the code that I have in my "httpd-vhosts.conf" file.
<VirtualHost *:80>
ServerAdmin blah#blah.com
ServerName blah.blah.com
ServerAlias blah blah.blah.local
ErrorLog "logs/blah-error.log"
CustomLog "logs/blah-access.log" common
ErrorDocument 503 "D:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/blah/error.html"
LogLevel warn
RewriteEngine On
JkMount /* worker5
DocumentRoot "D:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/blah"
<Directory "D:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/blah">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
In the "httpd.conf" file, it is including the "httpd-vhosts.conf" file, so I don't know why it is not working. Any help would be appreciated. Thanks.
ErrorDocument takes in a absolute URL path instead of a file path. So it should be:
ErrorDocument 503 /blah/error.html
Assuming under your document root is a /blah/error.html file.

Custom error page in Apache2 for 401

Here's the relevant part of the .htaccess file:
AuthUserFile /var/www/mywebsite/.htpasswd
AuthGroupFile /dev/null
AuthName protected
AuthType Basic
Require valid-user
ErrorDocument 400 /var/www/errors/index.html
ErrorDocument 401 /var/www/errors/index.html
ErrorDocument 403 /var/www/errors/index.html
ErrorDocument 404 /var/www/errors/index.html
ErrorDocument 500 /var/www/errors/index.html
Docuement root is set to /var/www/mywebsite/web, it's on of many vhosts. I can navigate to the index.html page.
All I'm seeing is the generic Apache 401 page, any thoughts.
EDIT: This is the error message in my browser:
Authorization Required
This server could not verify that you
are authorized to access the document
requested. Either you supplied the
wrong credentials (e.g., bad
password), or your browser doesn't
understand how to supply the
credentials required.
Additionally, a 401 Authorization
Required error was encountered while
trying to use an ErrorDocument to
handle the request. Apache/2.2.9
(Debian) PHP/5.2.6-1+lenny8 with
Suhosin-Patch Server at www.dirbe.com
Port 80
Make sure that /var/www/errors is readable by the apache user and include this in your apache configuration:
<Directory /var/www/errors>
Order allow,deny
Allow from all
</Directory>
ErrorDocument takes in a absolute URL path instead of a file path. So it should be:
ErrorDocument 404 /error/error.html
Assuming under your document root is a /error/error.html file.
This question (and answers and comments) helped me a bunch, thanks much!
I solved a slightly different way, and wanted to share. In this case, we needed to provide a custom 401 error document and the root path needed to be proxied to a backend app.
So, for example, http://example.com needed to serve content from http://internal-server:8080/. Also, http://example.com needed to be protected using Basic Auth with a custom 401 error document.
So, I created a directory named "error" in the DocumentRoot. Here's the relevant lines from the vhost:
ErrorDocument 401 /error/error401.html
# Grant access to html files under /error
<Location "/error">
Options -Indexes
Order Deny,Allow
Allow from all
</Location>
# restrict proxy using basic auth
<Proxy *>
Require valid-user
AuthType basic
AuthName "Basic Auth"
AuthUserFile /etc/apache2/.htpasswd
</Proxy>
# Proxy everything except for /error
ProxyRequests Off
ProxyPass /error !
ProxyPass / http://internal:8080/
ProxyPassReverse / http://internal:8080/