Partage
  • Partager sur Facebook
  • Partager sur Twitter

Redirection http-https

Sujet résolu
    30 septembre 2021 à 15:51:37

    Bonjour,

    je suis le cours Gérez votre serveur linux et ses services, précisément à la partie Sécurisez votre serveur Web.

    Problème: la redirection d'une requête http en https ne semble pas fonctionner.

    Prérequis:

    • port 80,443 TCP ouvert… et d'autres…;
    • mes deux machines test sont en VM, le serveur Ubuntu server 20.04, le client CentOS8, aucun problème de réseau.

    Les données:

    Comme je n'ai pas de nom de domaine, ainsi je n'ai pas pu demander de certificat à une autorité de certification officielle… J'ai donc fabriqué (manière de dire :) ) une clé privée (privkey.pem) et un certificat autosigné (fullchain.pem) comme ceci:

    thierry@vm-serveur:~/certificat$ pwd
    /home/thierry/certificat
    thierry@vm-serveur:~/certificat$ openssl req -x509 -newkey rsa:4096 -nodes -keyout privkey.pem -out fullchain.pem -days 365
    Generating a RSA private key
    .........................................................................................................++++
    .....................++++
    writing new private key to 'privkey.pem'
    -----
    You are about to be asked to enter information that will be incorporated
    into your certificate request.
    What you are about to enter is what is called a Distinguished Name or a DN.
    There are quite a few fields but you can leave some blank
    For some fields there will be a default value,
    If you enter '.', the field will be left blank.
    -----
    Country Name (2 letter code) [AU]:
    State or Province Name (full name) [Some-State]:
    Locality Name (eg, city) []:
    Organization Name (eg, company) [Internet Widgits Pty Ltd]:
    Organizational Unit Name (eg, section) []:
    Common Name (e.g. server FQDN or YOUR name) []:www.example.com
    Email Address []:webmaster@example.com
    


    Résultat:

    thierry@vm-serveur:~/certificat$ ll
    total 16
    drwxrwxr-x 2 thierry thierry 4096 Sep 30 12:41 ./
    drwxr-xr-x 4 thierry thierry 4096 Sep 30 12:45 ../
    -rw-rw-r-- 1 thierry thierry 2114 Sep 30 13:10 fullchain.pem
    -rw------- 1 thierry thierry 3272 Sep 30 13:09 privkey.pem
    

    mon fichier /etc/apache2/sites-available/01-www.example.com.conf  :

    thierry@vm-serveur:/etc/apache2/sites-available$ cat 01-www.example.com.conf
    <VirtualHost *:80>
            ServerName www.example.com
            ServerAlias example.com
            ServerAdmin webmaster@example.com
    
            <IfModule mod_rewrite.c>
                    RewriteEngine On
                    RewriteCond %{HTTPS} !=on
                    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
            </IfModule>
    
    </Virtualhost>
    
    
    <IfModule mod_ssl.c>
    <VirtualHost *:443>
            # The ServerName directive sets the request scheme, hostname and port that
            # the server uses to identify itself. This is used when creating
            # redirection URLs. In the context of virtual hosts, the ServerName
            # specifies what hostname must appear in the request's Host: header to
            # match this virtual host. For the default virtual host (this file) this
            # value is not decisive as it is used as a last resort host regardless.
            # However, you must set it for any further virtual host explicitly.
            ServerName www.example.com
            ServerAlias example.com
    
            # On active le chiffrement (HTTPS)
            SSLEngine                   On
            SSLCertificateFile          /home/thierry/certificat/fullchain.pem
            SSLCertificateKeyFile       /home/thierry/certificat/privkey.pem
    
            ServerAdmin webmaster@example.com
            DocumentRoot /var/www/html/www.example.com
    
            # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
            # error, crit, alert, emerg.
            # It is also possible to configure the loglevel for particular
            # modules, e.g.
            #LogLevel info ssl:warn
    
            ErrorLog ${APACHE_LOG_DIR}/www.example.com-error.log
            CustomLog ${APACHE_LOG_DIR}/www.example.com-access.log combined
    
            # For most configuration files from conf-available/, which are
            # enabled or disabled at a global level, it is possible to
            # include a line for only one particular virtual host. For example the
            # following line enables the CGI configuration for this host only
            # after it has been globally disabled with "a2disconf".
            #Include conf-available/serve-cgi-bin.conf
    
            <Directory /var/www/html/www.example.com>
                    Options All
                    AllowOverride None
            </Directory>
    
            #<Directory /var/www/html/www.example.com/top_secret>
            #       AuthType Basic
            #       AuthName "Accès retreint aux utilisateurs authentifiés"
            #       AuthBasicProvider file
            #       AuthUserFile "/etc/apache2/passwords"
            #       Require ip 192.168.0.122
            #       Require valid-user
            #</Directory>
    
            <Directory /var/www/html/www.example.com/top_secret>
                    AuthType Basic
                    AuthName "Accès retreint aux utilisateurs authentifiés"
                    AuthBasicProvider ldap
                    AuthLDAPURL ldap://localhost/ou=Personnes,dc=mon-entreprise,dc=com?uid?sub
                    Require ip 192.168.0.122
                    Require valid-user
            </Directory>
    
    
    </VirtualHost>
    </IfModule>
    # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
    

    et puis:

    thierry@vm-serveur:~$ ll /var/www/html/www.example.com/
    total 24
    drwxr-xr-x 3 root root  4096 Sep 29 14:09 ./
    drwxr-xr-x 3 root root  4096 Sep 29 13:45 ../
    -rw-r--r-- 1 root root 10918 Sep 29 13:45 index.html
    drwxr-xr-x 2 root root  4096 Sep 29 14:10 top_secret/
    

    Comme le certificat est autosigné, ça a chougnié, j'ai autorisé ce certificat à être dans la liste de confiance…

    Aucun soucis en https:


    Par contre, ça n'a pas l'air de fonctionner comme attendu en http, je suis toujours en http non ?

    Merci pour votre aide. :)



    -
    Edité par DenebeDenebe 30 septembre 2021 à 15:55:15

    • Partager sur Facebook
    • Partager sur Twitter
      4 octobre 2021 à 17:19:52

      Je ne sais pas trop pourquoi, mais maintenant ça marche.

      J'ai dû certainement oublié de recharger apache, ou bien une ligne de /etc/hosts dans la machine du client firefox.

      Je ne sais pas trop, mais ça marche :)

      -
      Edité par DenebeDenebe 4 octobre 2021 à 17:20:12

      • Partager sur Facebook
      • Partager sur Twitter

      Redirection http-https

      × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
      × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
      • Editeur
      • Markdown