【问题标题】:How to enable SSL only on specified XAMPP directories如何仅在指定的 XAMPP 目录上启用 SSL
【发布时间】:2014-01-10 22:02:56
【问题描述】:

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

我有两个想要不同的目录,

c:/XAMPP/htdocs/PLACEHOLDER1 
c:/XAMPP/htdocs/PLACEHOLDER2

我想知道是否可以将 SSL 范围限制在一个目录中,例如在本例中为“placeholder1”。

这是我第一次使用 SSL,如有任何混淆,请见谅。

【问题讨论】:

    标签: apache ssl xampp


    【解决方案1】:

    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>
    

    将某些文件夹的“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
    

    让它看起来像这样:

    LoadModule rewrite_module modules/mod_rewrite.so
    

    现在,将以下文本粘贴到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>
    

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

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

    【讨论】:

      猜你喜欢
      • 2011-08-13
      • 2017-06-15
      • 2012-08-23
      • 2017-03-12
      • 2021-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-01
      相关资源
      最近更新 更多