User Tools

Site Tools


informatica:linux:apache2

Differences

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

Link to this comparison view

Next revision
Previous revision
informatica:linux:apache2 [2012/11/08 09:21] – creado javiinformatica:linux:apache2 [2018/02/17 19:44] (current) javi
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 427: Line 489:
  
 De momento no sale De momento no sale
 +
  
 ===== Virtualhosts ===== ===== Virtualhosts =====
Line 541: Line 604:
  
   apache2ctl restart   apache2ctl restart
 +
 +===== Modulos =====
 +
 +  * Listar modulos:
 +
 +<code>
 +sudo apachectl -t -D DUMP_MODULES
 +
 +Loaded Modules:
 + core_module (static)
 + log_config_module (static)
 + logio_module (static)
 + mpm_prefork_module (static)
 + http_module (static)
 + so_module (static)
 + alias_module (shared)
 + auth_basic_module (shared)
 + authn_file_module (shared)
 + authz_default_module (shared)
 + authz_groupfile_module (shared)
 + authz_host_module (shared)
 + authz_user_module (shared)
 + autoindex_module (shared)
 + cgi_module (shared)
 + deflate_module (shared)
 + dir_module (shared)
 + env_module (shared)
 + mime_module (shared)
 + negotiation_module (shared)
 + php5_module (shared)
 + reqtimeout_module (shared)
 + setenvif_module (shared)
 +Syntax OK
 +</code>
 +
 +  * Obtener el nombre del modulo necesario para los comandos 'a2dismod' o 'a2enmod':
 +
 +<code>
 +sudo a2enmod 
 +
 +Your choices are: actions alias asis auth_basic auth_digest authn_alias authn_anon authn_dbd authn_dbm authn_default authn_file authnz_ldap authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cern_meta cgi cgid charset_lite dav dav_fs dav_lock dbd deflate dir disk_cache dump_io env expires ext_filter file_cache filter headers ident imagemap include info ldap log_forensic mem_cache mime mime_magic negotiation php5 proxy proxy_ajp proxy_balancer proxy_connect proxy_ftp proxy_http proxy_scgi reqtimeout rewrite setenvif speling ssl status substitute suexec unique_id userdir usertrack version vhost_alias
 +Which module(s) do you want to enable (wildcards ok)?
 +</code>
 +
 +  * Deshabilitar modulo:
 +
 +<code>
 +sudo a2dismod status
 +
 +Module status disabled.
 +Run '/etc/init.d/apache2 restart' to activate new configuration!
 +</code>
 +
 +Y recargamos configuracion:
 +
 +  sudo apachectl graceful
 +  
 +===== Habilitar campos "last modified" etc. en listado de directorios =====
 +
 +En la imagen de docker por defecto NO aparecen esos atributos. Cambios:
 +
 +   /usr/local/apache2/conf/httpd.conf
 +
 +Descomentar esta linea:
 +
 +  Include conf/extra/httpd-autoindex.conf
 +  
 +===== 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.1352366503.txt.gz · Last modified: 2015/04/13 20:19 (external edit)