如何仅在指定的XAMPP目录上启用SSL

Let*_*h0_ 1 apache xampp ssl

我已经能够使用makecert创建一个自签名证书,该证书目前在C:// XAMPP/htdocs中的所有目录上启用HTTPS

我有两个目录,我想要与众不同,

c:/XAMPP/htdocs/PLACEHOLDER1 
c:/XAMPP/htdocs/PLACEHOLDER2
Run Code Online (Sandbox Code Playgroud)

我想知道是否有可能将SSL范围限制在一个目录中,比如在这种情况下'placeholder1'.

这是我第一次使用SSL,对任何困惑都很抱歉.

Da *_*boy 5

http://robsnotebook.com/xampp-ssl-encrypt-passwords提供了一些有关如何仅通过SSL加密访问文件夹的良好信息.它具体涵盖了这两个项目,这不是一个直接的引用,而是回答你的问题的本质的摘录:

使用SSL加密只能访问文件夹
首先,我们需要告知Apache您要加密的文件夹应始终使用加密(并且永远不会明确).这是通过<Directory>在配置文件中的每个所需列表中放置一个SSLRequireSSL指令来实现的(可以将它放在最后,就在它之前</Directory>).

Alias /web_folder_name "C:/xampp/foldername"
<Directory "C:/xampp/foldername">
    ...
    ...
    SSLRequireSSL
</Directory>
Run Code Online (Sandbox Code Playgroud)

对于某些文件夹,将"http"重定向到"https"

下一个可选步骤是将"http"请求重定向到我们想要保护的页面的"https"请求.这更加用户友好,并允许您在键入地址时仍然使用http(并自动切换到https://和加密).如果您不这样做,并且您使用了SSLRequireSSL,则只能通过键入https://来访问这些页面.这很好,可能更安全一点,但不是那么用户友好.要完成重定向,我们将使用mod_rewrite,以便我们不必在配置文件的这一部分中使用服务器名称.这有助于减少配置文件中写入服务器名称的位置数(使配置文件更易于维护).

首先,我们需要确保启用mod_rewrite.要执行此操作,请编辑c:\xampp\apache\conf\httpd.conf并删除#此行中的注释(字符):

#LoadModule rewrite_module modules/mod_rewrite.so
Run Code Online (Sandbox Code Playgroud)

使它看起来像这样:

LoadModule rewrite_module modules/mod_rewrite.so
Run Code Online (Sandbox Code Playgroud)

现在,将以下文本粘贴到顶部c:\xampp\apache\conf\extra\httpd-xampp.conf:

<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]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

如果您要将其他文件夹重定向到https://,请在下面添加通用文本(但替换您的文件夹名称):

# Redirect /folder_name folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} folder_name
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
Run Code Online (Sandbox Code Playgroud)