-*- coding: utf-8 -*-
Changes with Apache 2.5.0
+ *) mod_proxy_protocol: Add server-side, front-end support for PROXY PROTOCOL
+ (http://blog.haproxy.com/haproxy/proxy-protocol/). [roadrunner2]
+
*) mod_proxy_fcgi: Return HTTP 504 rather than 503 in case of proxy timeout.
[Luca Toscano]
+++ /dev/null
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" lang="es" xml:lang="es"><head>
-<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" />
-<!--
- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- This file is generated from xml source: DO NOT EDIT
- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- -->
-<title>Tutorial del Servidor Apache HTTP: Ficheros .htaccess - Servidor HTTP Apache Versión 2.5</title>
-<link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
-<link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
-<link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="../style/css/prettify.css" />
-<script src="../style/scripts/prettify.min.js" type="text/javascript">
-</script>
-
-<link href="../images/favicon.ico" rel="shortcut icon" /></head>
-<body id="manual-page"><div id="page-header">
-<p class="menu"><a href="../mod/">Módulos</a> | <a href="../mod/quickreference.html">Directivas</a> | <a href="http://wiki.apache.org/httpd/FAQ">Preguntas Frecuentes</a> | <a href="../glossary.html">Glosario</a> | <a href="../sitemap.html">Mapa del sitio web</a></p>
-<p class="apache">Versión 2.5 del Servidor HTTP Apache</p>
-<img alt="" src="../images/feather.png" /></div>
-<div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
-<div id="path">
-<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">Servidor HTTP</a> > <a href="http://httpd.apache.org/docs/">Documentación</a> > <a href="../">Versión 2.5</a> > <a href="./">How-To / Tutoriales</a></div><div id="page-content"><div id="preamble"><h1>Tutorial del Servidor Apache HTTP: Ficheros .htaccess</h1>
-<div class="toplang">
-<p><span>Idiomas disponibles: </span><a href="../en/howto/htaccess.html" hreflang="en" rel="alternate" title="English"> en </a> |
-<a href="../es/howto/htaccess.html" title="Español"> es </a> |
-<a href="../fr/howto/htaccess.html" hreflang="fr" rel="alternate" title="Français"> fr </a> |
-<a href="../ja/howto/htaccess.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
-<a href="../ko/howto/htaccess.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
-<a href="../pt-br/howto/htaccess.html" hreflang="pt-br" rel="alternate" title="Português (Brasil)"> pt-br </a></p>
-</div>
-
- <p>Los ficheros <code>.htaccess</code> facilitan una forma de realizar
- cambios en la configuración en contexto directorio.</p>
-</div>
-<div id="quickview"><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#related">Ficheros .htaccess</a></li>
-<li><img alt="" src="../images/down.gif" /> <a href="#what">Qué son/Cómo usarlos</a></li>
-<li><img alt="" src="../images/down.gif" /> <a href="#when">Cuando (no) usar ficheros .htaccess</a></li>
-<li><img alt="" src="../images/down.gif" /> <a href="#how">How directives are applied</a></li>
-<li><img alt="" src="../images/down.gif" /> <a href="#auth">Ejemplo de Autenticación</a></li>
-<li><img alt="" src="../images/down.gif" /> <a href="#ssi">Ejemplo de Server Side Includes</a></li>
-<li><img alt="" src="../images/down.gif" /> <a href="#rewrite">Reglas de Rewrite en ficheros .htaccess</a></li>
-<li><img alt="" src="../images/down.gif" /> <a href="#cgi">Ejemplo de CGI</a></li>
-<li><img alt="" src="../images/down.gif" /> <a href="#troubleshoot">Resolución de problemas</a></li>
-</ul><h3>Consulte también</h3><ul class="seealso"><li><a href="#comments_section">Comentarios</a></li></ul></div>
-<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
-<div class="section">
-<h2><a name="related" id="related">Ficheros .htaccess</a></h2>
- <table class="related"><tr><th>Módulos Relacionados</th><th>Directivas Relacionadas</th></tr><tr><td><ul><li><code class="module"><a href="../mod/core.html">core</a></code></li><li><code class="module"><a href="../mod/mod_authn_file.html">mod_authn_file</a></code></li><li><code class="module"><a href="../mod/mod_authz_groupfile.html">mod_authz_groupfile</a></code></li><li><code class="module"><a href="../mod/mod_cgi.html">mod_cgi</a></code></li><li><code class="module"><a href="../mod/mod_include.html">mod_include</a></code></li><li><code class="module"><a href="../mod/mod_mime.html">mod_mime</a></code></li></ul></td><td><ul><li><code class="directive"><a href="../mod/core.html#accessfilename">AccessFileName</a></code></li><li><code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code></li><li><code class="directive"><a href="../mod/core.html#options">Options</a></code></li><li><code class="directive"><a href="../mod/mod_mime.html#addhandler">AddHandler</a></code></li><li><code class="directive"><a href="../mod/core.html#sethandler">SetHandler</a></code></li><li><code class="directive"><a href="../mod/mod_authn_core.html#authtype">AuthType</a></code></li><li><code class="directive"><a href="../mod/mod_authn_core.html#authname">AuthName</a></code></li><li><code class="directive"><a href="../mod/mod_authn_file.html#authuserfile">AuthUserFile</a></code></li><li><code class="directive"><a href="../mod/mod_authz_groupfile.html#authgroupfile">AuthGroupFile</a></code></li><li><code class="directive"><a href="../mod/mod_authz_core.html#require">Require</a></code></li></ul></td></tr></table>
-
- <div class="note">Debería evitar usar ficheros <code>.htaccess</code> completamente si
- tiene acceso al fichero de configuración principal de httpd. Usar ficheros
- <code>.htaccess</code> ralentiza su servidor Apache http. Cualquier
- directiva que pueda incluir en un fichero <code>.htaccess</code>
- estará mejor configurada dentro de una sección
- <code class="directive"><a href="../mod/core.html#directory">Directory</a></code>, tendrá el mismo efecto y
- mejor rendimiento.</div>
-</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
-<div class="section">
-<h2><a name="what" id="what">Qué son/Cómo usarlos</a></h2>
-
-
- <p>Los ficheros <code>.htaccess</code> (o "ficheros de configuración
- distribuida") facilitan una forma de realizar cambios en la configuración
- en contexto directorio. Un fichero, que contiene una o más directivas, se
- coloca en un documento específico de un directorio, y estas directivas
- aplican a ese directorio y todos sus subdirectorios.</p>
-
- <div class="note"><h3>Nota:</h3>
- <p>Si quiere llamar a su fichero <code>.htaccess</code> de otra manera,
- puede cambiar el nombre del fichero usando la directiva <code class="directive"><a href="../mod/core.html#accessfilename">AccessFileName</a></code>. Por ejemplo, si usted prefiere
- llamar al fichero <code>.config</code>, entonces puede poner lo siguiente
- en el fichero de configuración de su servidor:</p>
-
- <pre class="prettyprint lang-config">AccessFileName ".config"</pre>
-
- </div>
-
- <p>Generalmente, los ficheros <code>.htaccess</code> usan la misma sintáxis
- que los <a href="../configuring.html#syntax">ficheros de la configuración
- principal</a>. Lo que puede utilizar en estos ficheros lo determina la
- directiva <code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code>. Esta directiva
- especifica, en categorías, qué directivas tendrán efecto si se encuentran en
- un fichero <code>.htaccess</code>. Si se permite una directiva en un fichero
- <code>.htaccess</code>, la documentación para esa directiva contendrá una
- sección Override, especificando qué valor debe ir en
- <code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code> para que se permita esa
- directiva.</p>
-
- <p>Por ejemplo, si busca en la documentación la directiva <code class="directive"><a href="../mod/core.html#adddefaultcharset">AddDefaultCharset</a></code>, encontrará que se permite en
- ficheros <code>.htaccess</code>. (Vea la línea de Contexto en el sumario de
- la directiva.) La línea <a href="../mod/directive-dict.html#Context">Override</a> muestra
- <code>FileInfo</code>. De este modo, debe tener al menos
- <code>AllowOverride FileInfo</code> para que esta directiva se aplique en
- ficheros <code>.htaccess</code>.</p>
-
- <div class="example"><h3>Ejemplo:</h3><table>
- <tr>
- <td><a href="../mod/directive-dict.html#Context">Context:</a></td>
- <td>server config, virtual host, directory, .htaccess</td>
- </tr>
-
- <tr>
- <td><a href="../mod/directive-dict.html#Override">Override:</a></td>
- <td>FileInfo</td>
- </tr>
- </table></div>
-
- <p>Si no está seguro de cuándo, una directiva en concreto, se puede usar en un
- fichero <code>.htaccess</code>, consulte la documentación para esa directiva,
- y compruebe la línea Context buscando ".htaccess".</p>
- </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
-<div class="section">
-<h2><a name="when" id="when">Cuando (no) usar ficheros .htaccess</a></h2>
-
- <p>Generalmente, solo debería usar ficheros <code>.htaccess</code> cuando no
- tiene acceso al fichero principal de configuración del servidor. Hay, por
- ejemplo, una creencia errónea de que la autenticación de usuario debería
- hacerse siempre dentro de ficheros <code>.htaccess</code>, y, más recientemente, otra creencia errónea de que las directivas de
- <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> deben ir en ficheros <code>.htaccess</code>.
- Esto sencillamente no es el caso. Puede poner las configuraciones de
- autenticación de usuario en la configuración principal del servidor, y esto
- es de hecho, el método preferido de configurar Apache. Del mismo modo, las
- directivas <code>mod_rewrite</code> funcionan mejor, en muchos sentidos, en
- el fichero de configuración principal del servidor.</p>
-
- <p>Los ficheros <code>.htaccess</code> deberían usarse cuando su proveedor
- de contenidos le permite hacer modificaciones de configuración
- en contexto directorio, pero usted no tiene acceso de root en el servidor.
- En el caso de que el administrador no esté dispuesto a hacer cambios
- frecuentes en la configuración, puede que sea necesario permitir a usuarios
- individuales realizar estos cambios de configuración en ficheros
- <code>.htaccess</code> por ellos mismos. Lo cual ocurre a menudo, por
- ejemplo, en casos donde los ISP están albergando múltiples sitios web de
- usuario en una sola máquina, y quieren que sus usuarios tengan la
- posibilidad de modificar sus configuraciones.</p>
-
- <p>Aun así, generalmente, el uso de ficheros <code>.htaccess</code> debería
- evitarse cuando sea posible. Cualquier configuración que consideraría poner
- en un fichero <code>.htaccess</code>, puede usarse con la misma efectividad
- en una sección <code class="directive"><a href="../mod/core.html#directory"><Directory></a></code> en el fichero de configuración
- del servidor.</p>
-
- <p>Hay dos razones para evitar el uso de ficheros <code>.htaccess</code>.</p>
-
- <p>La primera es el rendimiento. Cuando <code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code>
- está configurado para permitir el uso de ficheros <code>.htaccess</code>,
- httpd buscará ficheros <code>.htaccess</code> en cada directorio. Así,
- permitiendo ficheros <code>.htaccess</code> provoca una pérdida de
- rendimiento, ¡incluso aunque no los use! Además, los ficheros
- <code>.htaccess</code> se cargan cada vez que se solicita un documento.</p>
-
- <p>Además tenga en cuenta que httpd debe buscar ficheros
- <code>.htaccess</code> en todos los directorios de mayor jerarquía,
- para poder terner la lista completa de directivas que debe aplicar. (Vea
- la sección sobre <a href="#how">Cómo se aplican las directivas</a>.) Así, si
- se solicita un fichero de un directorio <code>/www/htdocs/example</code>,
- httpd debe buscar los siguientes ficheros:</p>
-
- <div class="example"><p><code>
- /.htaccess<br />
- /www/.htaccess<br />
- /www/htdocs/.htaccess<br />
- /www/htdocs/example/.htaccess
- </code></p></div>
-
- <p>De esta manera, por cada acceso a un fichero de ese directorio, hay 4
- accesos adicionales al sistema de ficheros, incluso si ninguno de esos
- ficheros está presente. (Tenga en cuenta que este caso solo se daría si los
- ficheros <code>.htaccess</code> están activados en <code>/</code>, que
- generalmente no es el caso.).</p>
-
- <p>En el caso de las directivas <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code>, en el contexto de
- <code>.htaccess</code> estas expresiones regulares deben recompilarse con
- cada solicitud a ese directorio, cuando en el contexto de configuración del
- servidor solo se compilan una vez y se cachean. Adicionalmente, las reglas
- en sí mismas son más complicadas, puesto que uno debe sortear las
- restricciones que vienen acompañadas del contexto directorio y
- <code>mod_rewrite</code>. Consulte la <a href="../rewrite/intro.html#htaccess">Guía de Rewrite</a> para un mayor
- detalle sobre este tema.</p>
-
- <p>La segunda consideración es de seguridad. Estará permitiendo que usuarios
- modifiquen la configuración del servidor, lo cual puede dar lugar a cambios sobre los que usted no tendrá ningún control. Medite profundamente si debe
- dar a sus usuarios ese privilegio. Además tenga en cuenta que dar a los usuarios menos privilegios de los que necesitan dará lugar a más peticiones
- de soporte. Asegúrese de que le indica a sus usuarios claramente el nivel de privilegios que les está dando. Especificando exactamente cómo ha
- configurado <code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code>, e invíteles
- a revisar la documentación relacionada, lo cual le ahorrará
- bastantes confusiones más adelante.</p>
-
- <p>Tenga en cuenta que esto es equivalente por completo a poner un fichero
- <code>.htaccess</code> en un directorio <code>/www/htdocs/example</code>
- con una directiva, y poner la misma directiva en una sección
- Directory <code><Directory "/www/htdocs/example"></code> en su
- configuración principal del servidor:</p>
-
- <p>Fichero <code>.htaccess</code> en <code>/www/htdocs/example</code>:</p>
-
- <div class="example"><h3>Contenido de fichero .htaccess en
- <code>/www/htdocs/example</code></h3><pre class="prettyprint lang-config">AddType text/example ".exm"</pre>
-</div>
-
- <div class="example"><h3>Sección de su fichero <code>httpd.conf</code></h3><pre class="prettyprint lang-config"><Directory "/www/htdocs/example">
- AddType text/example ".exm"
-</Directory></pre>
-</div>
-
- <p>Aun así, poniendo ésta en el fichero de configuración dará como resultado
- una menor pérdida de rendimiento, y como la configuración se carga una vez
- cuando el httpd arranca, en lugar de cada vez que se solicita un fichero.</p>
-
- <p>El uso de ficheros <code>.htaccess</code> puede desactivarse por completo
- configurando la directiva <code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code>
- a <code>none</code>:</p>
-
- <pre class="prettyprint lang-config">AllowOverride None</pre>
-
-</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
-<div class="section">
-<h2><a name="how" id="how">How directives are applied</a></h2>
-
- <p>Las directivas de configuración que se encuentran en el fichero
- <code>.htaccess</code> se aplican al directorio en el que el fichero
- <code>.htaccess</code> se encuentra, y a todos sus subdirectorios. Sin
- embargo, es importante recordar que puede haber otros ficheros
- <code>.htaccess</code> en directorios previos. Las directivas se aplican en
- el orden en el que se encuentran. Por lo tanto, un fichero
- <code>.htaccess</code> puede sobrescribir directivas que se encuentran
- en ficheros <code>.htaccess</code> que se encuentran en directorios previos
- del árbol de directorios. Y estos, en cambio, pueden haber sobrescrito
- directivas que se encontraban más arriba, o en el fichero principal de
- configuración del servidor mismo.</p>
-
- <p>Ejemplo:</p>
-
- <p>En el directorio <code>/www/htdocs/example1</code> tenemos un fichero
- <code>.htaccess</code> que contiene lo siguiente:</p>
-
- <pre class="prettyprint lang-config">Options +ExecCGI</pre>
-
-
- <p>(Nota: debe terner "<code>AllowOverride Options</code>" configurado para
- permitir el uso de la directiva "<code class="directive"><a href="../mod/core.html#options">Options</a></code>" en ficheros
- <code>.htaccess</code> files.)</p>
-
- <p>En el directorio <code>/www/htdocs/example1/example2</code> tenemos un
- fichero <code>.htaccess</code> que contiene:</p>
-
- <pre class="prettyprint lang-config">Options Includes</pre>
-
-
- <p>Por este segundo fichero <code>.htaccess</code>, en el directorio
- <code>/www/htdocs/example1/example2</code>, la ejecución de CGI execution no
- está permitida, porque solo se ha definido <code>Options Includes</code>,
- que sobrescribe completamente una configuración previa que se pudiera haber
- definido.</p>
-
- <h3><a name="merge" id="merge">Incorporando el .htaccess en los ficheros de
- configuración principal</a></h3>
-
- <p>Como se ha comentado en la documentación en las <a href="../sections.html">Secciones de Configuración</a>, los ficheros
- <code>.htaccess</code> pueden sobrescribir las secciones <code class="directive"><a href="../mod/core.html#directory"><Directory></a></code> por el directorio
- correspondiente, pero se sobrescribirán por otros tipos de secciones de
- configuración de los ficheros de configuración principal. Este hecho se
- puede usar para forzar ciertas configuraciones, incluso en presencia
- de una configuración laxa de
- <code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code>. Por ejemplo, para
- prevenir la ejecución de un script mientras se permite cualquier otra cosa
- en <code>.htaccess</code> puede usar:</p>
-
- <pre class="prettyprint lang-config"><Directory "/www/htdocs">
- AllowOverride All
-</Directory>
-
-<Location "/">
- Options +IncludesNoExec -ExecCGI
-</Location></pre>
-
-
- <div class="note">Este ejemplo asume que su <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code> es <code>/www/htdocs</code>.</div>
-
-
-</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
-<div class="section">
-<h2><a name="auth" id="auth">Ejemplo de Autenticación</a></h2>
-
- <p>Si saltó directamente a esta parte del documento para averiguar como
- hacer la autenticación, es important que tenga en cuenta una cosa. Hay una
- creencia errónea de que necesita usar ficheros <code>.htaccess</code> para
- configurar autenticación con contraseña. Este no es el caso. Colocar las
- directivas de autenticación en una sección
- <code class="directive"><a href="../mod/core.html#directory"><Directory></a></code>, en su fichero
- de configuración principal, es el método recomendado para configurar esto,
- y los ficheros <code>.htaccess</code> deberían usarse solamente si no tiene
- acceso al fichero de configuración principal del servidor. Vea <a href="#when">más arriba</a> una explicación de cuando debería y cuando no
- debería usar ficheros <code>.htaccess</code>.</p>
-
- <p>Dicho esto, si todavía cree que debe usar el fichero
- <code>.htaccess</code>, podrá ver que una configuración como la que sigue
- podría servirle.</p>
-
- <p>Contenido del fichero <code>.htaccess</code>:</p>
-
- <pre class="prettyprint lang-config">AuthType Basic
-AuthName "Password Required"
-AuthUserFile "/www/passwords/password.file"
-AuthGroupFile "/www/passwords/group.file"
-Require group admins</pre>
-
-
- <p>Tenga en cuenta que <code>AllowOverride AuthConfig</code> debe estar
- habilitado para que estas directivas tengan algún efecto.</p>
-
- <p>Por favor vea el <a href="auth.html">tutorial de autenticación</a> para
- una explicación más completa de la autenticación y la autorización.</p>
-</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
-<div class="section">
-<h2><a name="ssi" id="ssi">Ejemplo de Server Side Includes</a></h2>
-
- <p>Otro uso común de ficheros <code>.htaccess</code> es activar Server Side
- Includes para un directorio en particular. Esto puede hacerse
- con las siguientes directivas de configuración, colocadas en un fichero
- <code>.htaccess</code> y el directorio deseado:</p>
-
- <pre class="prettyprint lang-config">Options +Includes
-AddType text/html "shtml"
-AddHandler server-parsed shtml</pre>
-
-
- <p>Tenga en cuenta que <code>AllowOverride Options</code> y
- <code>AllowOverride FileInfo</code> deben estar activadas para que estas
- directivas tengan efecto.</p>
-
- <p>Por favor vea el <a href="ssi.html">tutorial de SSI</a> para una
- explicación más completa de server-side includes.</p>
-</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
-<div class="section">
-<h2><a name="rewrite" id="rewrite">Reglas de Rewrite en ficheros .htaccess</a></h2>
- <p>Cuando use <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> en
- ficheros <code>.htaccess</code>, tenga en cuenta que el contexto
- directorio cambia las cosas un poco. En concreto, las reglas son
- relativas al directorio actual, en lugar de serlo de la petición de URI
- solicitada originalmente.
- Considere los siguientes ejemplos:</p>
-
-<pre class="prettyprint lang-config"># En httpd.conf
-RewriteRule "^/images/(.+)\.jpg" "/images/$1.png"
-
-# En .htaccess en el directorio raíz
-RewriteRule "^images/(.+)\.jpg" "images/$1.png"
-
-# En .htaccess en images/
-RewriteRule "^(.+)\.jpg" "$1.png"</pre>
-
-
- <p>En un <code>.htaccess</code> en cualquier directorio del DocumentRoot, la
- barra ("/") inicial se elimina del valor facilitado a <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code>, y en el subdirectorio
- <code>images</code>, se elimina <code>/images/</code> también de este valor.
- Así, su expresión regular necesita omitir también esa parte.</p>
-
- <p>Consulte la <a href="../rewrite/">documentación de mod_rewrite</a> para
- más detalles al usar <code>mod_rewrite</code>.</p>
-
-</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
-<div class="section">
-<h2><a name="cgi" id="cgi">Ejemplo de CGI</a></h2>
-
- <p>Finalmente, puede que quiera usar un fichero <code>.htaccess</code> para
- permitir la ejecución de programas CGI en un directorio en particular. Esto
- se puede implementar con la siguiente configuración:</p>
-
- <pre class="prettyprint lang-config">Options +ExecCGI
-AddHandler cgi-script "cgi" "pl"</pre>
-
-
- <p>Alternativamente, si quiere considerar como programas CGI todos los
- ficheros de un directorio concreto, esto se puede conseguir con la siguiente
- configuración:</p>
-
- <pre class="prettyprint lang-config">Options +ExecCGI
-SetHandler cgi-script</pre>
-
-
- <p>Tenga en cuenta que <code>AllowOverride Options</code> y
- <code>AllowOverride FileInfo</code> deben estar ambas activadas para que
- estas directivas tengan efecto.</p>
-
- <p>Por favor vea el <a href="cgi.html">tutorial CGI</a> para mayor detalle
- sobre programación y configuración de CGI.</p>
-
-</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
-<div class="section">
-<h2><a name="troubleshoot" id="troubleshoot">Resolución de problemas</a></h2>
-
- <p>Cuando pone directivas en un fichero <code>.htaccess</code> y no obtiene
- el efecto deseado hay una serie de cosas que pueden haber ido mal.</p>
-
- <p>El problema más común es que <code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride
- </a></code> no está configurada para que sus directivas puedan surtir
- efecto. Asegúrese de que no tiene <code>AllowOverride None</code>
- configurado para el directorio en cuestión. Una buena forma de probar esto
- es poner "basura" en su fichero <code>.htaccess</code> y recargar la página.
- Si no se genera un error en el servidor, casi seguro que tiene configurado
- <code>AllowOverride None</code>.</p>
-
- <p>Si, por otro lado, obtiene errores de servidor al intentar acceder a
- documentos, compruebe el log de errores de httpd. Seguramente le indiquen
- que la directiva en uso en su fichero <code>.htaccess</code> no está
- permitida.</p>
-
- <div class="example"><p><code>
- [Fri Sep 17 18:43:16 2010] [alert] [client 192.168.200.51] /var/www/html/.htaccess: DirectoryIndex not allowed here
- </code></p></div>
-
- <p>Esto indicará que o bien ha usado una directiva que no se permite nunca
- en ficheros <code>.htaccess</code>, o que simplementa no tiene
- <code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code> configurado
- a un nivel suficiente para la directiva que ha usado. Consulte la
- documentación para esa directiva en particular para determinar cual es el
- caso.</p>
-
- <p>Alternativamente, puede que le indique que hay un error de sintaxis en
- el uso de la propia directiva.</p>
-
- <div class="example"><p><code>
- [Sat Aug 09 16:22:34 2008] [alert] [client 192.168.200.51] /var/www/html/.htaccess: RewriteCond: bad flag delimiters
- </code></p></div>
-
- <p>En este caso, el mensaje de error debería ser específico para el error de
- sintaxis concreto que ha cometido.</p>
-
-</div></div>
-<div class="bottomlang">
-<p><span>Idiomas disponibles: </span><a href="../en/howto/htaccess.html" hreflang="en" rel="alternate" title="English"> en </a> |
-<a href="../es/howto/htaccess.html" title="Español"> es </a> |
-<a href="../fr/howto/htaccess.html" hreflang="fr" rel="alternate" title="Français"> fr </a> |
-<a href="../ja/howto/htaccess.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
-<a href="../ko/howto/htaccess.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
-<a href="../pt-br/howto/htaccess.html" hreflang="pt-br" rel="alternate" title="Português (Brasil)"> pt-br </a></p>
-</div><div class="top"><a href="#page-header"><img src="../images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comentarios</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
-<script type="text/javascript"><!--//--><![CDATA[//><!--
-var comments_shortname = 'httpd';
-var comments_identifier = 'http://httpd.apache.org/docs/trunk/howto/htaccess.html';
-(function(w, d) {
- if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
- d.write('<div id="comments_thread"><\/div>');
- var s = d.createElement('script');
- s.type = 'text/javascript';
- s.async = true;
- s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
- (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
- }
- else {
- d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
- }
-})(window, document);
-//--><!]]></script></div><div id="footer">
-<p class="apache">Copyright 2016 The Apache Software Foundation.<br />Licencia bajo los términos de la <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
-<p class="menu"><a href="../mod/">Módulos</a> | <a href="../mod/quickreference.html">Directivas</a> | <a href="http://wiki.apache.org/httpd/FAQ">Preguntas Frecuentes</a> | <a href="../glossary.html">Glosario</a> | <a href="../sitemap.html">Mapa del sitio web</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--
-if (typeof(prettyPrint) !== 'undefined') {
- prettyPrint();
-}
-//--><!]]></script>
-</body></html>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0"?>
+<!DOCTYPE modulesynopsis SYSTEM "http://httpd.apache.org/docs/2.4/style/modulesynopsis.dtd">
+<?xml-stylesheet type="text/xsl" href="http://httpd.apache.org/docs/2.4/style/manual.en.xsl"?>
+
+<!--
+ Copyright 2014 Cloudzilla Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<modulesynopsis metafile="mod_proxy_protocol.xml.meta">
+
+<name>mod_proxy_protocol</name>
+<description>Implements the server side of the proxy protocol.</description>
+<status>Extension</status>
+<sourcefile>mod_proxy_protocol.c</sourcefile>
+<identifier>proxy_protocol_module</identifier>
+
+<summary>
+ <p><module>mod_proxy_protocol</module> implements the server side of
+ HAProxy's
+ <a href="http://blog.haproxy.com/haproxy/proxy-protocol/">Proxy Protocol</a>.</p>
+
+ <p>The module overrides the client IP address for the connection
+ with the information supplied by the upstream proxy in the proxy
+ protocol (connection) header.</p>
+
+ <p>This overridden useragent IP address is then used for the
+ <module>mod_authz_host</module>
+ <directive module="mod_authz_core" name="require">Require ip</directive>
+ feature, is reported by <module>mod_status</module>, and is recorded by
+ <module>mod_log_config</module> <code>%a</code> and <module>core</module>
+ <code>%a</code> format strings. The underlying client IP of the connection
+ is available in the <code>%{c}a</code> format string.</p>
+
+ <note type="warning">It is critical to only enable this behavior from
+ intermediate proxies which are trusted by this server, since it is trivial
+ for the remote client to impersonate another client. Currently this must
+ be done by external means (such as a firewall) as this module does not
+ (yet) implement access controls.</note>
+</summary>
+<seealso><a href="http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt">Proxy Protocol Spec</a></seealso>
+
+<directivesynopsis>
+<name>ProxyProtocol</name>
+<description>Enable or disable the proxy protocol handling</description>
+<syntax>ProxyProtocol On|Off</syntax>
+<contextlist><context>server config</context><context>virtual host</context>
+</contextlist>
+
+<usage>
+ <p>The <directive>ProxyProtocol</directive> enables or disables the
+ reading and handling of the proxy protocol connection header. If enabled
+ the upstream client <em>must</em> send the header every time it opens a
+ connection or the connection will get aborted.</p>
+
+ <p>While this directive may be specified in any virtual host, it is
+ important to understand that because the proxy protocol is connection
+ based and protocol agnostic, the enabling and disabling is actually based
+ on ip-address and port. This means that if you have multiple name-based
+ virtual hosts for the same host and port, and you enable it any one of
+ them, then it is enabled for all them (with that host and port). It also
+ means that if you attempt to enable the proxy protocol in one and disable
+ in the other, that won't work; in such a case the last one wins and a
+ notice will be logged indicating which setting was being overridden.</p>
+
+ <highlight language="config">
+ ProxyProtocol On
+ </highlight>
+</usage>
+</directivesynopsis>
+
+<!--
+<directivesynopsis>
+<name>ProxyProtocolTrustedProxies</name>
+<description>A listed of clients that are trusted to provide the proxy
+protocol header.</description>
+<syntax>ProxyProtocolTrustedProxies <var>levels</var></syntax>
+<syntax>ProxyProtocolTrustedProxies all|<var>host</var> [<var>host</var>] ...</syntax>
+<default>ProxyProtocolTrustedProxies all</default>
+<contextlist><context>server config</context><context>virtual host</context>
+</contextlist>
+
+<usage>
+ <p>The <directive>ProxyProtocolTrustedProxies</directive> directive limits
+ which clients are trusted to use the proxy protocol. What happens when a
+ client is not trusted is controlled by the
+ <directive module="mod_proxy_protocol">ProxyProtocolRejectUntrusted</directive>
+ directive.</p>
+</usage>
+</directivesynopsis>
+
+<directivesynopsis>
+<name>ProxyProtocolRejectUntrusted</name>
+<description>The number of characters in subdirectory names</description>
+<syntax>ProxyProtocolRejectUntrusted On|Off</syntax>
+<default>ProxyProtocolRejectUntrusted On</default>
+<contextlist><context>server config</context><context>virtual host</context>
+</contextlist>
+
+<usage>
+ <p>The <directive>ProxyProtocolRejectUntrusted</directive> directive
+ controls the behavior when a connection is received from an untrusted
+ client (as configured by the
+ <directive module="mod_proxy_protocol">ProxyProtocolTrustedProxies</directive>
+ directive) on a host and port for which the proxy protocol has been enabled.
+ If set to On (the default) then the connection is aborted; if set to Off
+ then the connection is allowed, and client must send a valid proxy protocol
+ header, but the contents of the header are ignored and the client IP for
+ the connection left untouched (i.e. will be that of the immediate client).
+ </p>
+</usage>
+</directivesynopsis>
+-->
+
+</modulesynopsis>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<metafile reference="mod_proxy_protocol.xml">
+ <basename>mod_proxy_protocol</basename>
+ <path>/mod/</path>
+ <relpath>https://httpd.apache.org/docs/2.4</relpath>
+</metafile>
--- /dev/null
+/*
+ * Copyright 2014 Cloudzilla Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * mod_proxy_protocol.c -- Apache proxy_protocol module
+ *
+ * This implements the server side of the proxy protocol decribed in
+ * http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt . It works
+ * by installing itself (where enabled) as a connection filter (ahead of
+ * mod_ssl) to parse and remove the proxy protocol header, and by then
+ * modifying the useragent_* fields in the requests accordingly.
+ *
+ * TODO:
+ * * add the following configs:
+ * ProxyProtocolTrustedProxies "all"|ip-addr|host [ip-addr|host] ... (default all)
+ * ProxyProtocolRejectUntrusted Yes|No (default Yes)
+ * What to do if a connection is received from an untrusted proxy:
+ * yes = abort the connection
+ * no = allow connection and remove header, but ignore header
+ * * add support for sending the header on outgoing connections (mod_proxy),
+ * and config for choosing which hosts to enable it for
+ * (ProxyProtocolDownstreamHosts?)
+ */
+
+#include "httpd.h"
+#include "http_config.h"
+#include "http_protocol.h"
+#include "http_connection.h"
+#include "http_main.h"
+#include "http_log.h"
+#include "ap_config.h"
+#include "ap_listen.h"
+#include "apr_strings.h"
+
+module AP_MODULE_DECLARE_DATA proxy_protocol_module;
+
+/*
+ * Module configuration
+ */
+
+typedef struct pp_addr_info {
+ struct pp_addr_info *next;
+ apr_sockaddr_t *addr;
+ server_rec *source;
+} pp_addr_info;
+
+typedef struct {
+ pp_addr_info *enabled;
+ pp_addr_info *disabled;
+ apr_pool_t *pool;
+} pp_config;
+
+static int pp_hook_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
+ apr_pool_t *ptemp)
+{
+ pp_config *conf;
+
+ conf = (pp_config *) apr_palloc(pconf, sizeof(pp_config));
+ conf->enabled = NULL;
+ conf->disabled = NULL;
+ conf->pool = pconf;
+
+ ap_set_module_config(ap_server_conf->module_config, &proxy_protocol_module,
+ conf);
+
+ return OK;
+}
+
+/* Similar apr_sockaddr_equal, except that it compares ports too. */
+static int pp_sockaddr_equal(apr_sockaddr_t *addr1, apr_sockaddr_t *addr2)
+{
+ return (addr1->port == addr2->port && apr_sockaddr_equal(addr1, addr2));
+}
+
+/* Similar pp_sockaddr_equal, except that it handles wildcard addresses
+ * and ports too.
+ */
+static int pp_sockaddr_compat(apr_sockaddr_t *addr1, apr_sockaddr_t *addr2)
+{
+ /* test exact address equality */
+ if (apr_sockaddr_equal(addr1, addr2) &&
+ (addr1->port == addr2->port || addr1->port == 0 || addr2->port == 0)) {
+ return 1;
+ }
+
+ /* test address wildcards */
+ if (apr_sockaddr_is_wildcard(addr1) &&
+ (addr1->port == 0 || addr1->port == addr2->port)) {
+ return 1;
+ }
+
+ if (apr_sockaddr_is_wildcard(addr2) &&
+ (addr2->port == 0 || addr2->port == addr1->port)) {
+ return 1;
+ }
+
+ return 0;
+}
+
+static int pp_addr_in_list(pp_addr_info *list, apr_sockaddr_t *addr)
+{
+ for (; list; list = list->next) {
+ if (pp_sockaddr_compat(list->addr, addr)) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+static void pp_warn_enable_conflict(pp_addr_info *prev, server_rec *new, int on)
+{
+ char buf[INET6_ADDRSTRLEN];
+
+ apr_sockaddr_ip_getbuf(buf, sizeof(buf), prev->addr);
+
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, new,
+ "ProxyProtocol: previous setting for %s:%hu from virtual "
+ "host {%s:%hu in %s} is being overriden by virtual host "
+ "{%s:%hu in %s}; new setting is '%s'",
+ buf, prev->addr->port, prev->source->server_hostname,
+ prev->source->addrs->host_port, prev->source->defn_name,
+ new->server_hostname, new->addrs->host_port, new->defn_name,
+ on ? "On" : "Off");
+}
+
+static const char *pp_enable_proxy_protocol(cmd_parms *cmd, void *config,
+ int flag)
+{
+ pp_config *conf;
+ server_addr_rec *addr;
+ pp_addr_info **add;
+ pp_addr_info **rem;
+ pp_addr_info *list;
+
+ conf = ap_get_module_config(ap_server_conf->module_config,
+ &proxy_protocol_module);
+
+ if (flag) {
+ add = &conf->enabled;
+ rem = &conf->disabled;
+ }
+ else {
+ add = &conf->disabled;
+ rem = &conf->enabled;
+ }
+
+ for (addr = cmd->server->addrs; addr; addr = addr->next) {
+ /* remove address from opposite list */
+ if (*rem) {
+ if (pp_sockaddr_equal((*rem)->addr, addr->host_addr)) {
+ pp_warn_enable_conflict(*rem, cmd->server, flag);
+ *rem = (*rem)->next;
+ }
+ else {
+ for (list = *rem; list->next; list = list->next) {
+ if (pp_sockaddr_equal(list->next->addr, addr->host_addr)) {
+ pp_warn_enable_conflict(list->next, cmd->server, flag);
+ list->next = list->next->next;
+ break;
+ }
+ }
+ }
+ }
+
+ /* add address to desired list */
+ if (!pp_addr_in_list(*add, addr->host_addr)) {
+ pp_addr_info *info = apr_palloc(conf->pool, sizeof(*info));
+ info->addr = addr->host_addr;
+ info->source = cmd->server;
+ info->next = *add;
+ *add = info;
+ }
+ }
+
+ return NULL;
+}
+
+static int pp_hook_post_config(apr_pool_t *pconf, apr_pool_t *plog,
+ apr_pool_t *ptemp, server_rec *s)
+{
+ pp_config *conf;
+ pp_addr_info *info;
+ char buf[INET6_ADDRSTRLEN];
+
+ conf = ap_get_module_config(ap_server_conf->module_config,
+ &proxy_protocol_module);
+
+ for (info = conf->enabled; info; info = info->next) {
+ apr_sockaddr_ip_getbuf(buf, sizeof(buf), info->addr);
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
+ "ProxyProtocol: enabled on %s:%hu", buf, info->addr->port);
+ }
+ for (info = conf->disabled; info; info = info->next) {
+ apr_sockaddr_ip_getbuf(buf, sizeof(buf), info->addr);
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
+ "ProxyProtocol: disabled on %s:%hu", buf, info->addr->port);
+ }
+
+ return OK;
+}
+
+static const command_rec proxy_protocol_cmds[] = {
+ AP_INIT_FLAG("ProxyProtocol", pp_enable_proxy_protocol, NULL, RSRC_CONF,
+ "Enable proxy-protocol handling (`on', `off')"),
+ { NULL }
+};
+
+/*
+ * Proxy-protocol implementation
+ */
+
+static const char *pp_inp_filter = "ProxyProtocol Filter";
+
+typedef struct {
+ char line[108];
+} proxy_v1;
+
+typedef union {
+ struct { /* for TCP/UDP over IPv4, len = 12 */
+ uint32_t src_addr;
+ uint32_t dst_addr;
+ uint16_t src_port;
+ uint16_t dst_port;
+ } ip4;
+ struct { /* for TCP/UDP over IPv6, len = 36 */
+ uint8_t src_addr[16];
+ uint8_t dst_addr[16];
+ uint16_t src_port;
+ uint16_t dst_port;
+ } ip6;
+ struct { /* for AF_UNIX sockets, len = 216 */
+ uint8_t src_addr[108];
+ uint8_t dst_addr[108];
+ } unx;
+} proxy_v2_addr;
+
+typedef struct {
+ uint8_t sig[12]; /* hex 0D 0A 0D 0A 00 0D 0A 51 55 49 54 0A */
+ uint8_t ver_cmd; /* protocol version and command */
+ uint8_t fam; /* protocol family and address */
+ uint16_t len; /* number of following bytes part of the header */
+ proxy_v2_addr addr;
+} proxy_v2;
+
+typedef union {
+ proxy_v1 v1;
+ proxy_v2 v2;
+} proxy_header;
+
+static const char v2sig[12] = "\x0D\x0A\x0D\x0A\x00\x0D\x0A\x51\x55\x49\x54\x0A";
+#define MIN_V1_HDR_LEN 15
+#define MIN_V2_HDR_LEN 16
+#define MIN_HDR_LEN MIN_V1_HDR_LEN
+
+typedef struct {
+ char header[sizeof(proxy_header)];
+ apr_size_t rcvd;
+ apr_size_t need;
+ int version;
+ ap_input_mode_t mode;
+ apr_bucket_brigade *bb;
+ int done;
+} pp_filter_context;
+
+typedef struct {
+ apr_sockaddr_t *client_addr;
+ char *client_ip;
+} pp_conn_config;
+
+static int pp_is_server_port(apr_port_t port)
+{
+ ap_listen_rec *lr;
+
+ for (lr = ap_listeners; lr; lr = lr->next) {
+ if (lr->bind_addr && lr->bind_addr->port == port) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+/* Add our filter to the connection.
+ */
+static int pp_hook_pre_connection(conn_rec *c, void *csd)
+{
+ pp_config *conf;
+ pp_conn_config *conn_conf;
+
+ /* check if we're enabled for this connection */
+ conf = ap_get_module_config(ap_server_conf->module_config,
+ &proxy_protocol_module);
+
+ if (!pp_addr_in_list(conf->enabled, c->local_addr) ||
+ pp_addr_in_list(conf->disabled, c->local_addr)) {
+ return DECLINED;
+ }
+
+ /* mod_proxy creates outgoing connections - we don't want those */
+ if (!pp_is_server_port(c->local_addr->port)) {
+ return DECLINED;
+ }
+
+ /* add our filter */
+ if (!ap_add_input_filter(pp_inp_filter, NULL, NULL, c)) {
+ return DECLINED;
+ }
+
+ ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, c,
+ "ProxyProtocol: enabled on connection to %s:%hu",
+ c->local_ip, c->local_addr->port);
+
+ /* this holds the resolved proxy info for this connection */
+ conn_conf = apr_pcalloc(c->pool, sizeof(*conn_conf));
+ ap_set_module_config(c->conn_config, &proxy_protocol_module, conn_conf);
+
+ return OK;
+}
+
+/* Set the request's useragent fields to our client info.
+ */
+static int pp_hook_post_read_request(request_rec *r)
+{
+ pp_conn_config *conn_conf;
+
+ conn_conf = ap_get_module_config(r->connection->conn_config,
+ &proxy_protocol_module);
+ if (!conn_conf || !conn_conf->client_addr) {
+ return DECLINED;
+ }
+
+ r->useragent_addr = conn_conf->client_addr;
+ r->useragent_ip = conn_conf->client_ip;
+
+ return OK;
+}
+
+typedef enum { HDR_DONE, HDR_ERROR, HDR_NEED_MORE } pp_parse_status_t;
+
+/*
+ * Human readable format:
+ * PROXY {TCP4|TCP6|UNKNOWN} <client-ip-addr> <dest-ip-addr> <client-port> <dest-port><CR><LF>
+ */
+static pp_parse_status_t pp_process_v1_header(conn_rec *c,
+ pp_conn_config *conn_conf,
+ proxy_header *hdr, apr_size_t len,
+ apr_size_t *hdr_len)
+{
+ char *end, *next, *word, *host, *valid_addr_chars, *saveptr;
+ char buf[sizeof(hdr->v1.line)];
+ apr_port_t port;
+ apr_status_t ret;
+ apr_int32_t family;
+
+#define GET_NEXT_WORD(field) \
+ word = apr_strtok(NULL, " ", &saveptr); \
+ if (!word) { \
+ ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, c, \
+ "ProxyProtocol: no " field " found in header '%s'", \
+ hdr->v1.line); \
+ return HDR_ERROR; \
+ }
+
+ end = memchr(hdr->v1.line, '\r', len - 1);
+ if (!end || end[1] != '\n') {
+ return HDR_NEED_MORE; /* partial or invalid header */
+ }
+
+ *end = '\0';
+ *hdr_len = end + 2 - hdr->v1.line; /* skip header + CRLF */
+
+ /* parse in separate buffer so have the original for error messages */
+ strcpy(buf, hdr->v1.line);
+
+ apr_strtok(buf, " ", &saveptr);
+
+ /* parse family */
+ GET_NEXT_WORD("family")
+ if (strcmp(word, "UNKNOWN") == 0) {
+ conn_conf->client_addr = c->client_addr;
+ conn_conf->client_ip = c->client_ip;
+ return HDR_DONE;
+ }
+ else if (strcmp(word, "TCP4") == 0) {
+ family = APR_INET;
+ valid_addr_chars = "0123456789.";
+ }
+ else if (strcmp(word, "TCP6") == 0) {
+ family = APR_INET6;
+ valid_addr_chars = "0123456789abcdefABCDEF:";
+ }
+ else {
+ ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, c,
+ "ProxyProtocol: unknown family '%s' in header '%s'",
+ word, hdr->v1.line);
+ return HDR_ERROR;
+ }
+
+ /* parse client-addr */
+ GET_NEXT_WORD("client-address")
+
+ if (strspn(word, valid_addr_chars) != strlen(word)) {
+ ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, c,
+ "ProxyProtocol: invalid client-address '%s' found in "
+ "header '%s'", word, hdr->v1.line);
+ return HDR_ERROR;
+ }
+
+ host = word;
+
+ /* parse dest-addr */
+ GET_NEXT_WORD("destination-address")
+
+ /* parse client-port */
+ GET_NEXT_WORD("client-port")
+ if (sscanf(word, "%hu", &port) != 1) {
+ ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, c,
+ "ProxyProtocol: error parsing port '%s' in header '%s'",
+ word, hdr->v1.line);
+ return HDR_ERROR;
+ }
+
+ /* parse dest-port */
+ /* GET_NEXT_WORD("destination-port") - no-op since we don't care about it */
+
+ /* create a socketaddr from the info */
+ ret = apr_sockaddr_info_get(&conn_conf->client_addr, host, family, port, 0,
+ c->pool);
+ if (ret != APR_SUCCESS) {
+ conn_conf->client_addr = NULL;
+ ap_log_cerror(APLOG_MARK, APLOG_ERR, ret, c,
+ "ProxyProtocol: error converting family '%d', host '%s',"
+ " and port '%hu' to sockaddr; header was '%s'",
+ family, host, port, hdr->v1.line);
+ return HDR_ERROR;
+ }
+
+ conn_conf->client_ip = apr_pstrdup(c->pool, host);
+
+ return HDR_DONE;
+}
+
+/* Binary format:
+ * <sig><cmd><proto><addr-len><addr>
+ * sig = \x0D \x0A \x0D \x0A \x00 \x0D \x0A \x51 \x55 \x49 \x54 \x0A
+ * cmd = <4-bits-version><4-bits-command>
+ * 4-bits-version = \x02
+ * 4-bits-command = {\x00|\x01} (\x00 = LOCAL: discard con info; \x01 = PROXY)
+ * proto = <4-bits-family><4-bits-protocol>
+ * 4-bits-family = {\x00|\x01|\x02|\x03} (AF_UNSPEC, AF_INET, AF_INET6, AF_UNIX)
+ * 4-bits-protocol = {\x00|\x01|\x02} (UNSPEC, STREAM, DGRAM)
+ */
+static pp_parse_status_t pp_process_v2_header(conn_rec *c,
+ pp_conn_config *conn_conf,
+ proxy_header *hdr)
+{
+ apr_status_t ret;
+ struct in_addr *in_addr;
+ struct in6_addr *in6_addr;
+
+ switch (hdr->v2.ver_cmd & 0xF) {
+ case 0x01: /* PROXY command */
+ switch (hdr->v2.fam) {
+ case 0x11: /* TCPv4 */
+ ret = apr_sockaddr_info_get(&conn_conf->client_addr, NULL,
+ APR_INET,
+ ntohs(hdr->v2.addr.ip4.src_port),
+ 0, c->pool);
+ if (ret != APR_SUCCESS) {
+ conn_conf->client_addr = NULL;
+ ap_log_cerror(APLOG_MARK, APLOG_ERR, ret, c,
+ "ProxyProtocol: error creating sockaddr");
+ return HDR_ERROR;
+ }
+
+ conn_conf->client_addr->sa.sin.sin_addr.s_addr =
+ hdr->v2.addr.ip4.src_addr;
+ break;
+
+ case 0x21: /* TCPv6 */
+ ret = apr_sockaddr_info_get(&conn_conf->client_addr, NULL,
+ APR_INET6,
+ ntohs(hdr->v2.addr.ip6.src_port),
+ 0, c->pool);
+ if (ret != APR_SUCCESS) {
+ conn_conf->client_addr = NULL;
+ ap_log_cerror(APLOG_MARK, APLOG_ERR, ret, c,
+ "ProxyProtocol: error creating sockaddr");
+ return HDR_ERROR;
+ }
+
+ memcpy(&conn_conf->client_addr->sa.sin6.sin6_addr.s6_addr,
+ hdr->v2.addr.ip6.src_addr, 16);
+ break;
+
+ default:
+ /* unsupported protocol, keep local connection address */
+ return HDR_DONE;
+ }
+ break; /* we got a sockaddr now */
+
+ case 0x00: /* LOCAL command */
+ /* keep local connection address for LOCAL */
+ return HDR_DONE;
+
+ default:
+ /* not a supported command */
+ ap_log_cerror(APLOG_MARK, APLOG_ERR, ret, c,
+ "ProxyProtocol: unsupported command %.2hx",
+ hdr->v2.ver_cmd);
+ return HDR_ERROR;
+ }
+
+ /* got address - compute the client_ip from it */
+ ret = apr_sockaddr_ip_get(&conn_conf->client_ip, conn_conf->client_addr);
+ if (ret != APR_SUCCESS) {
+ conn_conf->client_addr = NULL;
+ ap_log_cerror(APLOG_MARK, APLOG_ERR, ret, c,
+ "ProxyProtocol: error converting address to string");
+ return HDR_ERROR;
+ }
+
+ return HDR_DONE;
+}
+
+/* Determine if this is a v1 or v2 header.
+ */
+static int pp_determine_version(conn_rec *c, const char *ptr)
+{
+ proxy_header *hdr = (proxy_header *) ptr;
+
+ /* assert len >= 14 */
+
+ if (memcmp(&hdr->v2, v2sig, sizeof(v2sig)) == 0 &&
+ (hdr->v2.ver_cmd & 0xF0) == 0x20) {
+ return 2;
+ }
+ else if (memcmp(hdr->v1.line, "PROXY ", 6) == 0) {
+ return 1;
+ }
+ else {
+ ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, c,
+ "ProxyProtocol: no valid header found");
+ return -1;
+ }
+}
+
+/* Capture the first bytes on the protocol and parse the proxy protocol header.
+ * Removes itself when the header is complete.
+ */
+static apr_status_t pp_input_filter(ap_filter_t *f,
+ apr_bucket_brigade *bb_out,
+ ap_input_mode_t mode,
+ apr_read_type_e block,
+ apr_off_t readbytes)
+{
+ apr_status_t ret;
+ pp_filter_context *ctx = f->ctx;
+ pp_conn_config *conn_conf;
+ apr_bucket *b;
+ pp_parse_status_t psts;
+ const char *ptr;
+ apr_size_t len;
+
+ if (f->c->aborted) {
+ return APR_ECONNABORTED;
+ }
+
+ /* allocate/retrieve the context that holds our header */
+ if (!ctx) {
+ ctx = f->ctx = apr_palloc(f->c->pool, sizeof(*ctx));
+ ctx->rcvd = 0;
+ ctx->need = MIN_HDR_LEN;
+ ctx->version = 0;
+ ctx->mode = AP_MODE_READBYTES;
+ ctx->bb = apr_brigade_create(f->c->pool, f->c->bucket_alloc);
+ ctx->done = 0;
+ }
+
+ if (ctx->done) {
+ /* Note: because we're a connection filter we can't remove ourselves
+ * when we're done, so we have to stay in the chain and just go into
+ * passthrough mode.
+ */
+ return ap_get_brigade(f->next, bb_out, mode, block, readbytes);
+ }
+
+ conn_conf = ap_get_module_config(f->c->conn_config, &proxy_protocol_module);
+
+ /* try to read a header's worth of data */
+ while (!ctx->done) {
+ if (APR_BRIGADE_EMPTY(ctx->bb)) {
+ ret = ap_get_brigade(f->next, ctx->bb, ctx->mode, block,
+ ctx->need - ctx->rcvd);
+ if (ret != APR_SUCCESS) {
+ return ret;
+ }
+ }
+ if (APR_BRIGADE_EMPTY(ctx->bb)) {
+ return APR_EOF;
+ }
+
+ while (!ctx->done && !APR_BRIGADE_EMPTY(ctx->bb)) {
+ b = APR_BRIGADE_FIRST(ctx->bb);
+
+ ret = apr_bucket_read(b, &ptr, &len, block);
+ if (APR_STATUS_IS_EAGAIN(ret) && block == APR_NONBLOCK_READ) {
+ return APR_SUCCESS;
+ }
+ if (ret != APR_SUCCESS) {
+ return ret;
+ }
+
+ memcpy(ctx->header + ctx->rcvd, ptr, len);
+ ctx->rcvd += len;
+
+ apr_bucket_delete(b);
+ psts = HDR_NEED_MORE;
+
+ if (ctx->version == 0) {
+ /* reading initial chunk */
+ if (ctx->rcvd >= MIN_HDR_LEN) {
+ ctx->version = pp_determine_version(f->c, ctx->header);
+ if (ctx->version < 0) {
+ psts = HDR_ERROR;
+ }
+ else if (ctx->version == 1) {
+ ctx->mode = AP_MODE_GETLINE;
+ ctx->need = sizeof(proxy_v1);
+ }
+ else if (ctx->version == 2) {
+ ctx->need = MIN_V2_HDR_LEN;
+ }
+ }
+ }
+ else if (ctx->version == 1) {
+ psts = pp_process_v1_header(f->c, conn_conf,
+ (proxy_header *) ctx->header,
+ ctx->rcvd, &ctx->need);
+ }
+ else if (ctx->version == 2) {
+ if (ctx->rcvd >= MIN_V2_HDR_LEN) {
+ ctx->need = MIN_V2_HDR_LEN +
+ ntohs(((proxy_header *) ctx->header)->v2.len);
+ }
+ if (ctx->rcvd >= ctx->need) {
+ psts = pp_process_v2_header(f->c, conn_conf,
+ (proxy_header *) ctx->header);
+ }
+ }
+ else {
+ ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, f->c,
+ "ProxyProtocol: internal error: unknown version "
+ "%d", ctx->version);
+ f->c->aborted = 1;
+ apr_brigade_destroy(ctx->bb);
+ return APR_ECONNABORTED;
+ }
+
+ switch (psts) {
+ case HDR_ERROR:
+ f->c->aborted = 1;
+ apr_brigade_destroy(ctx->bb);
+ return APR_ECONNABORTED;
+
+ case HDR_DONE:
+ ctx->done = 1;
+ break;
+
+ case HDR_NEED_MORE:
+ break;
+ }
+ }
+ }
+
+ /* we only get here when done == 1 */
+ ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, f->c,
+ "ProxyProtocol: received valid header: %s:%hu",
+ conn_conf->client_ip, conn_conf->client_addr->port);
+
+ if (ctx->rcvd > ctx->need || !APR_BRIGADE_EMPTY(ctx->bb)) {
+ ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, f->c,
+ "ProxyProtocol: internal error: have data left over; "
+ " need=%lu, rcvd=%lu, brigade-empty=%d", ctx->need,
+ ctx->rcvd, APR_BRIGADE_EMPTY(ctx->bb));
+ f->c->aborted = 1;
+ apr_brigade_destroy(ctx->bb);
+ return APR_ECONNABORTED;
+ }
+
+ /* clean up */
+ apr_brigade_destroy(ctx->bb);
+ ctx->bb = NULL;
+
+ /* now do the real read for the upper layer */
+ return ap_get_brigade(f->next, bb_out, mode, block, readbytes);
+}
+
+static void proxy_protocol_register_hooks(apr_pool_t *p)
+{
+ /* mod_ssl is CONNECTION + 5, so we want something higher (earlier);
+ * mod_reqtimeout is CONNECTION + 8, so we want something lower (later) */
+ ap_register_input_filter(pp_inp_filter, pp_input_filter, NULL,
+ AP_FTYPE_CONNECTION + 7);
+
+ ap_hook_pre_config(pp_hook_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
+ ap_hook_post_config(pp_hook_post_config, NULL, NULL, APR_HOOK_MIDDLE);
+ ap_hook_pre_connection(pp_hook_pre_connection, NULL, NULL, APR_HOOK_MIDDLE);
+ ap_hook_post_read_request(pp_hook_post_read_request, NULL, NULL,
+ APR_HOOK_REALLY_FIRST);
+}
+
+/* Dispatch list for API hooks */
+AP_DECLARE_MODULE(proxy_protocol) = {
+ STANDARD20_MODULE_STUFF,
+ NULL, /* create per-dir config structures */
+ NULL, /* merge per-dir config structures */
+ NULL, /* create per-server config structures */
+ NULL, /* merge per-server config structures */
+ proxy_protocol_cmds, /* table of config file commands */
+ proxy_protocol_register_hooks /* register hooks */
+};