User Tools

Site Tools


informatica:linux:apache2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
informatica:linux:apache2 [2012/11/08 09:25] javiinformatica:linux:apache2 [2017/11/15 15:20] jose
Line 98: Line 98:
  
 ===== Proxy inverso ===== ===== Proxy inverso =====
 +
 +
 +
  
 ==== Habilitar módulos ==== ==== Habilitar módulos ====
 Hay que habilitar los módulos creando los enlaces simbólicos: Hay que habilitar los módulos creando los enlaces simbólicos:
-  /etc/apache2/mods-enabled+  # cd /etc/apache2/mods-enabled
  
 +  # ln -s ../mods-available/proxy_http.load
 +  # ln -s ../mods-available/proxy.load
 +  # ln -s ../mods-available/proxy.conf
 +  # ln -s  ../mods-available/rewrite.load
 +
 +  # ls -la
 +  
   proxy_http.load -> ../mods-available/proxy_http.load   proxy_http.load -> ../mods-available/proxy_http.load
   proxy.load -> ../mods-available/proxy.load   proxy.load -> ../mods-available/proxy.load
 +  proxy.conf -> ../mods-available/proxy.conf
   rewrite.load -> ../mods-available/rewrite.load   rewrite.load -> ../mods-available/rewrite.load
 +
 +También lo podemos habilitar con el comando:
 +  # a2enmod proxy_http
 +
 +  Considering dependency proxy for proxy_http:
 +  Enabling module proxy.
 +  Enabling module proxy_http.
 +  To activate the new configuration, you need to run:
 +    service apache2 restart
  
 ==== Creando el virtual Host ==== ==== Creando el virtual Host ====
Line 152: Line 172:
  
 ===== SSL ===== ===== SSL =====
 +
  
 ==== Habilitar los módulos de ssl en apache ==== ==== Habilitar los módulos de ssl en apache ====
  
-Crear enlace simbólico a ssl.conf y ssl.load en mods-enabled:+1Habilitar modulo SSL
  
-  #cd /etc/apache2/mods-enabled +  sudo a2enmod ssl
-  #ln -s ../mods-available/ssl.conf ssl.conf +
-  #ln -s ../mods-available/ssl.load ssl.load+
  
-o con+2. Generamos certificado
-  #a2enmod ssl +   
- +  openssl req $@ -newkey rsa:4096 -new -x509 -days 3650 -nodes -out /etc/apache2/apache.pem -keyout /etc/apache2/apache.key
-Generamos certificado: +
-  openssl req $@ -newkey rsa:4096 -new -x509 -days 3650 -nodes -out /etc/apache2/apache.pem -keyout /etc/apache2/apache.key+
  
 Otra forma: Otra forma:
-  #openssl req -new -x509 -days 365 -sha1 -newkey rsa:1024 -nodes -keyout server.key -out server.crt +   
 +  openssl req -new -x509 -days 365 -sha1 -newkey rsa:1024 -nodes -keyout server.key -out server.crt  
 <code> <code>
 # -x509 identifies that a certificate is required, rather than just a certificate request (see below). # -x509 identifies that a certificate is required, rather than just a certificate request (see below).
Line 177: Line 196:
 # -keyout and -out specify where to store the certificate and key. The key should be root-readable only; the certificate can be world-readable, and must be readable by the user that Apache runs as. # -keyout and -out specify where to store the certificate and key. The key should be root-readable only; the certificate can be world-readable, and must be readable by the user that Apache runs as.
 </code> </code>
- 
  
 Rellenamos los datos Rellenamos los datos
Line 189: Line 207:
  
  
-  #chmod 600 /etc/apache2/apache.pem+  sudo chmod 600 /etc/apache2/apache.pem
  
   <VirtualHost *:443>   <VirtualHost *:443>
Line 196: Line 214:
         SSLEngine on         SSLEngine on
                   SSLCertificateFile /etc/apache2/apache.pem                   SSLCertificateFile /etc/apache2/apache.pem
 +                  SSLCertificateKeyFile /etc/apache2/apache.key
 +
                   SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown                   SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
      
Line 220: Line 240:
   </VirtualHost>   </VirtualHost>
  
-==== Pedir un certificado ==== +==== Configurar autenticación con certificado personal ==== 
-Para pedir un certificado tenemos que poner lo siguiente:+Primero creamos la CA en el servidor 
 +  openssl genrsa -out ca.key 1024 
 +Luego una petición de certificado y lo firmamos: 
 +  openssl req -new -key ca.key -out ca.csr 
 +  openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt 
 + 
 +Ahora creamos el certificado para el apache: 
 +  openssl genrsa -out server.key 1024 
 +  openssl req -new -key server.key -out server.csr 
 +  openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt 
 + 
 + 
 + 
 +=== Cliente === 
 +Se genera un certificado que tiene que firmar la CA del servidor. Por ejemplo se puede crear desde un pc del usuario\\ 
 +Primero se genera la clave privada: 
 +  openssl genrsa -out client.key 1024 
 +Luego una request de certificado: 
 +  openssl req -new -key client.key -out client.csr -config openssl.cnf 
 + 
 +Se envía esta request al server para que la firme. Desde el servidor se firma: 
 +  openssl x509 -req -days 365 -CA ca.crt -CAkey ca.key -CAcreateserial -in client.csr -out client.crt 
 + 
 +Creamos el certificado con la clave privada y la clave pública: 
 +  openssl pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.p12 
 +Ahora importamos el p12 en el navegador 
 + 
 +He tenido que añadir esto en virtualhost para que valide el certificado: 
 +  SSLCACertificateFile /etc/apache2/ca/ca.crt 
 + 
 +Ahora en el servidor configuramos apache para que pida el certificado: 
 + 
 +<code> 
 +<Location /cert> 
 +   SSLRequireSSL 
 +   SSLVerifyClient require 
 +   SSLVerifyDepth 10 
 +</Location> 
 +</code> 
 + 
 +Podemos poner mas restricciones, por ejemplo por IP o por OU
 <code> <code>
 <Location /cert> <Location /cert>
Line 232: Line 292:
  
 Una de las condiciones de validación puede ser: Una de las condiciones de validación puede ser:
-          SSLRequire %{SSL_CLIENT_S_DN_OU} in {"CEPSA"} +Por OU 
 + SSLRequire %{SSL_CLIENT_S_DN_OU} in {"LEGIDO"} 
 +Por IP: 
 +  SSLRequire %{REMOTE_ADDR} =~ m/^2\.139\.211\.[0-9]+$/
  
 ==== Sacar información de un certificado: ==== ==== Sacar información de un certificado: ====
Line 598: Line 660:
  
   sudo apachectl graceful   sudo apachectl graceful
 +  
 +  
 +===== Redirecciones =====
 +
 +  * El dominio raiz (y solo el dominio raiz) se redirecciona a otra URL y se para de procesar mas reglas
 +  * Se pasan todas las peticiones a un backend Tomcat
 +
 +<code>
 + RewriteEngine on
 + RewriteRule ^/$ http://example.com/my-tomcat-app1/ [R=301,L]
 +
 + ProxyRequests off
 + ProxyPreserveHost on
 + ProxyPass         / http://localhost:8080/
 + ProxyPassReverse / http://localhost:8080/
 +</code>
 +
 +==== Herramientas online útiles ====
 +
 +  * Para generar:
 +
 +https://websiteadvantage.com.au/HtAccess-301-Redirect-Generator#heading-ToolResult
 +
 +  * Para detectar qué regla se aplica en función de la url que se pone:
 +
 +http://htaccess.mwl.be/be
 +
informatica/linux/apache2.txt · Last modified: 2018/02/17 19:44 by javi