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

时间:2016-12-17 17:14:10

标签: apache wamp

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

现在,我希望使用https://www.domain.com/subdomain/app1

访问我的网站而不是https://app1.domain.com

当我尝试访问该URL时,我会被要求选择客户端证书,但是当我选择匹配的证书时,我会收到错误403禁止。

当我使用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>

1 个答案:

答案 0 :(得分:1)

不是您的SSL设置允许403禁止。

</VirtualHost>块的末尾(DocumentRoot之前添加此内容,但只是将其置于首选位置)以授予访问<Directory "c:/wamp/www"> Order allow, deny Allow from all </Directory> 的权限虚拟主机的文件夹:

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

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

<Directory>

您还应检查先前的AllowOverride块中是否还有其他任何内容,以及之前的设置。例如,您可能需要Options或设置一些for D in $(find "$parent_dir" -maxdepth 2 -name "package.json"); do ( cd ${F%/*} && npm test ) || exit $? done ,但上述内容将解决您提出的问题。