我在 HTTP 上设置了这个虚拟主机,不同的域名将为来自不同位置的文件提供服务。这是我的000-default.conf
文件:
<VirtualHost *:80>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/root
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ServerName nature.sentenceman.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/nature
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ServerName games.sentenceman.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/games
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ServerName katiebenson.co.uk
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/katie
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
一切正常,正如您所看到的:
然后我意识到,当通过 HTTPS 访问它们时,所有文件都只会提供根文件,这是因为我没有在文件中复制这些虚拟主机000-default-le-ssl.conf
。但是,我现在已经这样做了,但它似乎仍然不起作用,如果你尝试通过 HTTPS 访问上述任何内容,你就会发现:
这个配置文件如下所示:
<IfModule mod_ssl.c>
<VirtualHost *:443>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/root
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName sentenceman.com
Include /etc/letsencrypt/options-ssl-apache.conf
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/sentenceman.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/sentenceman.com/privkey.pem
</VirtualHost>
<VirtualHost *:443>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ServerName nature.sentenceman.com
Include /etc/letsencrypt/options-ssl-apache.conf
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/sentenceman.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/sentenceman.com/privkey.pem
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/nature
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:433>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ServerName games.sentenceman.com
Include /etc/letsencrypt/options-ssl-apache.conf
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/sentenceman.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/sentenceman.com/privkey.pem
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/games
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:433>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ServerName katiebenson.co.uk
Include /etc/letsencrypt/options-ssl-apache.conf
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/sentenceman.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/sentenceman.com/privkey.pem
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/katie
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
</IfModule>
我已检查它是否已启用(我想否则我不应该得到任何东西HTTPS://
)。有人能看出这个设置有什么问题吗?
编辑:修复了接受答案中提到的错误端口后https://katiebenson.com现在有效!:D 另外两个不行,apache 错误日志告诉我原因:
[Sat Jul 25 17:54:11.755069 2020] [ssl:warn] [pid 27351] AH01909: games.sentenceman.com:443:0 server certificate does NOT include an ID which matches
the server name
[Sat Jul 25 17:54:11.755432 2020] [ssl:warn] [pid 27351] AH01909: nature.sentenceman.com:443:0 server certificate does NOT include an ID which matches
the server name
这些证书不是通配符证书(我下一步要做的事情是创建通配符证书)。
答案1
您的 HTTPS VirtualHostskatiebenson.co.uk
和games.sentenceman.com
是针对端口 433 定义的。实际的 HTTPS 端口是 443。