Personalizar Errores de Nuestro Apache2

5
Libreta: Libreta DEI Creado: 09/05/2012 08:18 a.m. Etiquetas: Web URLOrigen: http://www.amadourias.com/?p=101 Amado Urias G. » Personalizar los Errores de nuestro apache2 Este mini tutorial es para personalizar las páginas de errores que envia nuestro servidor cuando no existe una url o cualquier otro error. Además nos permitirá definir en qué idioma lo queremos ver. Personalizar el idioma de los Errores Primero tenemos que decirle a nuestro Apache2 que usaremos los errores personalizados, editando el archivo “/etc/apache2/conf.d/localized-error-pages” y nos aseguramos que el código dentro del grupo “<IfModule mod_negotiation.c>” esté descomentado: <IfModule mod_negotiation.c> <IfModule mod_include.c> <IfModule mod_alias.c> Alias /error/ "/usr/share/apache2/error/" ... LanguagePriority es en cs de fr it nl sv pt-br ro ... </IfModule> </IfModule> </IfModule> En la linea LanguagePriority es definimos el orden del idioma en que nos arrogará el error (es = Español). Segundo paso, tenemos que activar tres módulos de nuestro apache2 y lo hacemos como sigue: #a2enmod negotiation #a2enmod alias #a2enmod include Ahora tenemos que reiniciar nuestro apache2 y todo listo!

Transcript of Personalizar Errores de Nuestro Apache2

Page 1: Personalizar Errores de Nuestro Apache2

Libreta: Libreta DEICreado: 09/05/2012 08:18 a.m.Etiquetas: WebURLOrigen: http://www.amadourias.com/?p=101

Amado Urias G. » Personalizar los Errores de nuestroapache2

Este mini tutorial es para personalizar las páginas de errores que envia nuestro servidor cuandono existe una url o cualquier otro error. Además nos permitirá definir en qué idioma loqueremos ver.

Personalizar el idioma de los Errores

Primero tenemos que decirle a nuestro Apache2 que usaremos los errores personalizados,editando el archivo “/etc/apache2/conf.d/localized-error-pages” y nos aseguramos que elcódigo dentro del grupo “<IfModule mod_negotiation.c>” esté descomentado:

<IfModule mod_negotiation.c><IfModule mod_include.c><IfModule mod_alias.c>Alias /error/ "/usr/share/apache2/error/"...LanguagePriority es en cs de fr it nl sv pt-br ro...</IfModule></IfModule></IfModule>

En la linea LanguagePriority es definimos el orden del idioma en que nos arrogará el error (es= Español).

Segundo paso, tenemos que activar tres módulos de nuestro apache2 y lo hacemos como sigue:

#a2enmod negotiation#a2enmod alias#a2enmod include

Ahora tenemos que reiniciar nuestro apache2 y todo listo!

Page 2: Personalizar Errores de Nuestro Apache2

#/etc/init.d/apache2 reload

Para probar, pida ahora una url no valida a ese servidor y verá el mensaje personalizado.

Opcional: Para personalizar el correo del admin en el vhost defina esta variable:

ServerAdmin [email protected]

Personalizar las páginas de los Errores

Si queremos personalizar aún más las páginas de los errores tenemos que agregar código htmla los archivos usados como encabezado y pie de página que son usados por todas las llamadasde errores.

Para modificar el body y la parte superior de todos los errores, modificar el archivo fuente:

#vim /usr/share/apache2/error/include/top.html

Y para hacerlo con nuestros pies de páginas debemos de modificar el archivo:

#vim /usr/share/apache2/error/include/bottom.html

apache2

Page 3: Personalizar Errores de Nuestro Apache2

Libreta: Libreta DEICreado: 07/05/2012 11:52 a.m.Etiquetas: WebURLOrigen: http://stackoverflow.com/questions/4341263/custom-error-page-in-apache2-for-401

apache - Custom error page in Apache2 for 401 - Stack Overflow

Errores 400-500

PMV

2,552 1 4 16

2 Answers active oldest votes

1Here'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.htmlpage.

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 yousupplied the wrong credentials (e.g., bad password), or your browser doesn't understand how tosupply the credentials required.

Additionally, a 401 Authorization Required error was encountered while trying to use anErrorDocument to handle the request. Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny8 with Suhosin-PatchServer at www.dirbe.com Port 80

apache apache2 custom-error-pages

link | improve this question edited Dec 3 '10 at 0:34 asked Dec 2 '10 at 23:58

94% accept rate

feedback

Make sure that /var/www/errors is readable by the apache user and include this in your apacheconfiguration:

Page 4: Personalizar Errores de Nuestro Apache2

Sam C

2,246 4 11

1 <Directory /var/www/errors>

Order allow,deny

Allow from all

</Directory>

link | improve this answer answered Dec 3 '10 at 0:05

No luck. And nothing in any of the error logs. I am seeing this on the error page though: "Additionally, a 401Authorization Required error was encountered while trying to use an ErrorDocument to handle the request." – PMV Dec 3 '10 at 0:32

Try putting your require auth lines inside of a <Location /></Location> section. – Sam C Dec 3 '10 at 0:58

thanks for the hint, but no avail. Got an error: <Location not allowed here – PMV Dec 3 '10 at 1:25

1 The apache documentation says that ErrorDocument can be a path relative to the document root, or anexternal URL that will be sent with a redirect. Since you're getting an Auth required message you might needtwo adjacent directories, one at /errors, and one at /protected, where the .htaccess in /protected wouldreference /errors/401.html as the ErrorDocument. – Sam C Dec 3 '10 at 2:22

Sam's last comment solved my issue, so I've accepted his original answer. – PMV Dec 7 '10 at 19:31

feedback

0This 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 401error 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:

Page 5: Personalizar Errores de Nuestro Apache2

Dave Paroulek

3,095 9 20

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/

link | improve this answer answered Aug 30 '11 at 15:56

feedback

Your Answer

log inNameEmailHome Page

Not the answer you're looking for? Browse other questions tagged apache apache2

custom-error-pages or ask your own question.

or