I want to do something but I can't find an answer (Maybe I badly searched). I don't know if it is possible so say me if it's not.
I would like to limit an Apache virtual host to one and only domain name : bde.yggdrasil.cafe. So that if the user try to access this website using 90.90.3.57 or another domain name it is listed as not existing website. Here is my extra/bde.conf which is included in httpd.conf, you'll understand the problem:
<VirtualHost *:80>
ServerName bde.yggdrasil.cafe
ServerAdmin my@email.fr
DocumentRoot /srv/http/bdeweb
#Some django config
#[...]
RewriteEngine on
RewriteCond %{SERVER_NAME} =bde.yggdrasil.cafe
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Listen 443
<VirtualHost *:443>
ServerName bde.yggdrasil.cafe
ServerAdmin my@email.fr
DocumentRoot /srv/http/bdeweb
#Some django config
#[...]
SSLEngine on
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/bde.yggdrasil.cafe/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/bde.yggdrasil.cafe/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
If I use this code and I try to connect to 90.90.3.57 or yggdrasil.cafe using http protocol my request is caught by Django which returns an error 400 (It is good but not what I want to get). if I connect to bde.yggdrasil.cafe using http it redirect me correctly to https.
yggdrasil.cafe --> 90.90.3.57
bde.yggdrasil.cafe --> yggdrasil.cafe
<VirtualHost *:80>
ServerName bde.yggdrasil.cafe
RewriteEngine on
RewriteCond %{SERVER_NAME} =bde.yggdrasil.cafe
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Listen 443
<VirtualHost *:443>
ServerName bde.yggdrasil.cafe
ServerAdmin my@email.fr
DocumentRoot /srv/http/bdeweb
#Some django config
#[...]
SSLEngine on
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/bde.yggdrasil.cafe/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/bde.yggdrasil.cafe/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
If I try to connect to my server using 90.90.3.57 or yggdrasil.cafe I fall on "Indexes of /" (Which is bad, really bad).
I would like Apache to ignore the connection if the user doesn't user the subdomain "bde.yggdrasil.cafe".
Thanks for your time
As said by Dusan Basic
Of course, just add another VirtualHost with
ServerName yggdrasil.cafe
; for the beginning you can have simpleRewriteRule ^ - [F]
It fixed the problem :)