我想使用 Debian 9 和 Apache 2 在我的虚拟服务器上设置一个子域,它指向 /var/www/html/test 的目录。SSL 和 Let's Encrypt 也已启用,因此也应使用 https 访问子域。
我的000-default.conf
文件看起来像:
<VirtualHost _default_:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
<VirtualHost _default_:443>
DocumentRoot /var/www/html
ServerName www.example.com
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15768000; includeSubDomains; preload"
</IfModule>
SSLEngine on
ServerAlias www.example.com
SSLCertificateFile /etc/letsencrypt/live/www.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
该文件default-ssl.conf
如下所示:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
ServerName www.example.com
ServerAlias example.com
</VirtualHost>
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
我制作了该文件的新副本,000-default.conf
将其命名为“test.example.com.conf”并通过 a2ensite 启用它。该文件如下所示:
<VirtualHost _default_:80>
ServerAdmin webmaster@test.example.com
DocumentRoot /var/www/html/test
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
<VirtualHost _default_:443>
DocumentRoot /var/www/html/test
ServerName test.example.com
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15768000; includeSubDomains; preload"
</IfModule>
SSLEngine on
ServerAlias test.example.com
SSLCertificateFile /etc/letsencrypt/live/www.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
我的hosts
文件包括条目SERVER_IP_ADDRESS test.example.com
.
DNS 服务器有一个“A”条目,其中 test.example.com 指向SERVER_IP_ADDRESS
.
从另一台机器 ping test.example.com 以“找不到主机”结束,并且在虚拟服务器上 ping 会导致自身响应。
那么为什么浏览器只显示“找不到服务器”呢?我是不是忘记了什么?我的配置有问题吗?