如何为 sub-domain.domain.com 配置客户端授权?

How do I configure client authorization for sub-domain.domain.com?

我有为特定子文件夹生成的带有客户端身份验证的 wamp 服务器:

现在,我想使用 https://app1.domain.com

访问我的站点而不是 https://www.domain.com/subdomain/app1

当我尝试访问 url 时,我确实被要求选择客户端证书,但是当我选择匹配的证书时,我收到错误 403 forbidden。

当我使用 OpenSSL 生成我的证书时,我使用 *.domain.com 作为服务器密钥的 CN。

这是我在 httpd-ssl.conf

中的虚拟主机定义
<VirtualHost *:443>
ServerName www.domain.com:443
DocumentRoot "c:/wamp/www"
ServerAdmin admin@domain.com

ErrorLog "C:/wamp/bin/apache/apache2.4.9/logs/ssl_error.log"
TransferLog "C:/wamp/bin/apache/apache2.4.9/logs/ssl_access.log"

SSLEngine on
SSLVerifyClient require
SSLVerifyDepth 10

SSLCertificateFile "C:\wamp\bin\apache\apache2.4.9\conf\cert\server.cer"
SSLCertificateKeyFile "C:\wamp\bin\apache\apache2.4.9\conf\cert\server.key"
SSLCACertificateFile "C:\wamp\bin\apache\apache2.4.9\conf\cert\ca.cer"

<LocationMatch ^(?=.*/subomain/app1/)(?!.*/subdomain/app1/service).*>
    SSLRequire %{SSL_CLIENT_S_DN_CN} eq "App1Key"
</LocationMatch>    

<FilesMatch "\.(cgi|shtml|phtml|php)$">
    SSLOptions +StdEnvVars
</FilesMatch>

BrowserMatch "MSIE [2-5]" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0

CustomLog "c:/wamp/bin/apache/apache2.4.9/logs/ssl_request.log" "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>

此外,我创建了这个 vhosts.conf 以允许 subdomain.domain.com

<VirtualHost *:80>
    ServerName www.domain.com
    ServerAlias *.domain.com
    VirtualDocumentRoot "C:\wamp\www\demo\%1"
    ErrorLog "logs\errors.log"
    <directory "C:\wamp\www\demo\%1">
        Options  FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from all
    </directory>
</VirtualHost>

更新

我已根据答案将以下代码添加到 ssl.conf,但现在客户端证书始终有效并且它忽略了 LocationMatch

的条件
<directory "C:\wamp\www\demo\%1">
        Options  FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from all
    </directory>

假设我想要以下等同于 subdomain.domain.com

的标准
<LocationMatch ^(?=.*/subomain/app1//)(?!.*/subomain/app1//service).*>
        #SSLOptions +StdEnvVars +ExportCertData
        SSLRequire %{SSL_CLIENT_S_DN_CN} eq "Shob"
    </LocationMatch>

不是您的 SSL 设置导致 403 被禁止。

将此添加到 <VirtualHost> 块的末尾(就在 </VirtualHost> 之前,尽管将其放在那里只是一种偏好)以授予访问 DocumentRoot 文件夹的权限虚拟主机:

<Directory "c:/wamp/www">
    Order allow, deny
    Allow from all
</Directory>

或者,如果您使用的是 Apache 2.4 或更高版本:

<Directory "c:/wamp/www">
    Require all granted
</Directory>

您还应该检查在之前的 <Directory> 块中是否还有其他设置,并将其也带入。例如,您可能需要 AllowOverride 或设置一些 Options,但以上将解决您询问的问题。