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
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
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
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.