Xampp Localhost 上的 SSL 在 Windows 上使用 VirtualHost 重定向到 Xampp 默认 info/localhost 页面

SSL on Xampp Localhost using VirtualHost on Windows redirects to Xampp default info/localhost page

我已经阅读了很多关于在 Xampp/Windows/Apache/VirtualHost 上配置 SSL 的帖子,并且认为我做对了,但是当我进入虚拟主机 url (q.localhost) 时,我始终进入默认的本地主机 Xampp 信息页面,该页面显示:url 栏中的“http://q.localhost/xampp/”。

以下是我认为相关的各种文件中的内容:

阿帕奇 httpd.conf:

LoadModule ssl_module modules/mod_ssl.so

Apache httpd-vhosts.conf:

<Directory C:/vhost>
    AllowOverride All
    Require all granted
</Directory>

#this is the default address of XAMPP    
<VirtualHost *:80>
    DocumentRoot "C:/XAMPP/htdocs/"
    ServerName localhost
</VirtualHost>

#this is the first vhost address in XAMPP
<VirtualHost *:443>
    DocumentRoot "C:/XAMPP/htdocs/data/anycompany"
    ServerName q.localhost
    <Directory "C:/XAMPP/htdocs/data/anycompany">
        AllowOverride All
        Order Deny,Allow   
        Allow from all 
    </Directory>
    SSLEngine On
    SSLCertificateFile "C:/xampp/apache/conf/ssl.crt/server.crt"
    SSLCertificateKeyFile "C:/xampp/apache/conf/ssl.key/server.key"
</VirtualHost>

###### THIS WORKS, BUT COMMENTED OUT REPLACED BY THE ABOVE  ########
#this is the first vhost address in XAMPP
#<VirtualHost *:80>
#    DocumentRoot "C:/XAMPP/htdocs/data/anycompany"
#    ServerName q.localhost
#</VirtualHost>

Windows 主机文件:

127.0.0.1       localhost
127.0.0.1       q.localhost
127.0.0.1       test.localhost

Apache httpd-ssl.conf:

DocumentRoot "C:/xampp/htdocs/data/anycompany"
ServerName q.localhost:443
ServerAdmin admin@localhost.com

正在使用 Apache 版本 1.8.3。 apache 错误日志中似乎没有任何错误消息。

已解决:

上面的配置似乎是正确的,但我没有意识到一件事,我必须包含一些进一步的配置才能使其工作。解释如下:

  1. 在 URL window 中键入 "q.localhost" 失败,并重定向到 Xampp 默认页面。必须在 url 之前包含 https://,因此输入“https://q.localhost”会显示正确的页面。但是,按要求点击网站上的其他各种link也失败了,而且没有link前面的"https://..."。

  2. 为了更正上述问题,我参考了这个article。建议将重定向添加到配置文件:\xampp\apache\conf\extra\httpd-xampp.conf。我添加了他建议的启用自动重定向的内容,而不必总是输入 "https://..."

    <IfModule mod_rewrite.c>

        RewriteEngine On
    
        # Redirect /xampp folder to https
        RewriteCond %{HTTPS} !=on
        RewriteCond %{REQUEST_URI} xampp
        RewriteRule ^(.*) https://%{SERVER_NAME} [R,L]
    
        # Redirect /phpMyAdmin folder to https
        RewriteCond %{HTTPS} !=on
        RewriteCond %{REQUEST_URI} phpmyadmin
        RewriteRule ^(.*) https://%{SERVER_NAME} [R,L]
    
        # Redirect /security folder to https
        RewriteCond %{HTTPS} !=on
        RewriteCond %{REQUEST_URI} security
        RewriteRule ^(.*) https://%{SERVER_NAME} [R,L]
    
        # Redirect /webalizer folder to https
        RewriteCond %{HTTPS} !=on
        RewriteCond %{REQUEST_URI} webalizer
        RewriteRule ^(.*) https://%{SERVER_NAME} [R,L]
    
        # Redirect /folder_name folder to https
        RewriteCond %{HTTPS} !=on
        RewriteCond %{REQUEST_URI} folder_name
        RewriteRule ^(.*) https://%{SERVER_NAME} [R,L]
    

    </IfModule>