在Windows上使用VirtualHost的Xampp Localhost上的SSL重定向到Xampp默认信息/本地主机页面

问题描述 投票:0回答:1

我已经阅读了很多有关在Xampp / Windows / Apache / VirtualHost上配置SSL的帖子,并认为我做对了,但是当我输入virtualhost url(q.localhost)时,我总是会使用默认的localhost Xampp信息页面,网址栏中显示为:“ http://q.localhost/xampp/”。

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

Apache 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 [email protected]

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

apache ssl virtualhost
1个回答
0
投票

已解决:

似乎上面的配置是正确的,但我没有意识到一件事,因此我必须添加一些其他配置才能使其正常工作。解释如下:

  1. 在URL窗口中键入“ q.localhost”失败,并重定向到Xampp默认页面。必须在网址前包含https://,因此输入“ https://q.localhost”将显示正确的页面。但是,按要求单击网站上的其他链接也失败,但链接前面没有“ 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}$1 [R,L]
    
        # Redirect /phpMyAdmin folder to https
        RewriteCond %{HTTPS} !=on
        RewriteCond %{REQUEST_URI} phpmyadmin
        RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
    
        # Redirect /security folder to https
        RewriteCond %{HTTPS} !=on
        RewriteCond %{REQUEST_URI} security
        RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
    
        # Redirect /webalizer folder to https
        RewriteCond %{HTTPS} !=on
        RewriteCond %{REQUEST_URI} webalizer
        RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
    
        # Redirect /folder_name folder to https
        RewriteCond %{HTTPS} !=on
        RewriteCond %{REQUEST_URI} folder_name
        RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
    

    </IfModule>

© www.soinside.com 2019 - 2024. All rights reserved.