User Tools

Site Tools


informatica:servidor_internet_2009_http_to_https_apache

Servidor web/dades

Actualització d'HTTP a HTTPS. Configuració d'Apache - Setembre de 2022

Un cop obtingut el certificat, creo múltiples servidors virtuals a Apache d'acord amb la recomanació descrita a Redirect Server Aliases to Server Name Over HTTPS on Apache | stackoverflow.com en què es proposa definir tres servidors virtuals:

  • el primer per redirigir HTTP a HTTPS;
  • el segon, que escolta en HTTPS, per redirigir tots els dominis cap al domini principal;
  • i el tercer, que només escolta en HTTPS, per configurar el domini principal.

Amb això s'aconsegueix simplificar la configuració del servidor HTTP/HTTPS.

If I got it correctly, you're trying to redirect every known domain reaching your apache to just one domain and when the connection comes as HTTP you want to redirect it to HTTPS.

To keep the configuration simple, I would create 3 different virtual hosts:

The first one will listen on http and include every domain you want to redirect (including the main one becuase it's listening on http). This virtualhost will redirect everything to the main domain over https:

    <VirtualHost *:80>
       ServerName main.site.com
       ServerAlias mysite.example.com
       ServerAlias another.site.com
       Redirect permanent / https://main.site.com/
    </VirtualHost>

The second one will listen on https port and includes all the domains but the main one and redirect it to your primary domain (it's like the previous one except it doesn't include the main domain)

<VirtualHost *:443>
   ServerName mysite.example.com
   ServerAlias another.site.com
   Redirect permanent / https://main.site.com/
      
   ...
   SSLEngine On
   ...
</VirtualHost>

In the end, the main one will just listen on https and will include only the main domain:

<VirtualHost *:443>
   ServerName main.site.com
     
   ...
   SSLEngine On
   ...
</VirtualHost>

This way, the only virtualhost requiring configuretiona (document root, locations, etc.) is the last one.

Servidor virtual 1: redireccionament d'HTTP a HTTPS

Creo el fitxer sermn_uab_cat-1-http.conf amb el següent contingut,

<VirtualHost *:80>
    ServerName sermn.uab.cat

    ServerAlias sermn.uab.es
    ServerAlias rmn3.uab.cat
    ServerAlias rmn3.uab.es

    Redirect permanent / https://sermn.uab.cat/
</VirtualHost>

Servidor virtual 2: redireccionament d'HTTPS al servidor principal

Creo el fitxer sermn_uab_cat-2-https.conf amb el següent contingut,

<VirtualHost *:443>
    ServerName sermn.uab.cat
    
    ServerAlias sermn.uab.es
    ServerAlias rmn3.uab.cat
    ServerAlias rmn3.uab.es

    Redirect permanent / https://sermn.uab.cat/
    
    #### SSL CERTIFICATES

    SSLEngine on
    SSLCertificateFile ...
    SSLCertificateKeyFile ...
</VirtualHost>

Servidor virtual 3: configuració del servidor HTTPS principal

Creo el fitxer sermn_uab_cat-3-https.conf amb el següent contingut,

<VirtualHost *:443>
    ServerName sermn.uab.cat
       
    #### SSL CERTIFICATES

    SSLEngine on
    SSLCertificateFile ...
    SSLCertificateKeyFile ...
    
    #### DOCUMENT ROOT

    DocumentRoot /var/www/sermn

    #### DIRECTORIES

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    ...
    
</VirtualHost>

Enllaços per proves

HTTP

Aplicacions web

HTTPS

Aplicacions web

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
informatica/servidor_internet_2009_http_to_https_apache.txt · Last modified: 2022/10/01 19:24 by miquel