Apache LDAP身份验证仅适用于某些虚拟主机

时间:2017-08-08 08:59:00

标签: apache centos virtualhost

我有一个在CentOS 7下运行Apache 2.4.6的网络服务器,其中我有几个网络资源。我想仅对其中一些应用LDAP身份验证,所以我尝试通过为每个资源创建一个虚拟主机并将LDAP身份验证仅配置为我想要的资源来实现。

这是我的尝试:

/etc/httpd/conf.d/test1.conf:

<VirtualHost *:80>
Servername server_name
DocumentRoot /var/www/html/test1

<Directory "/var/www/html/test1">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all

#LDAP
SetHandler php-script
Require all denied
AuthBasicProvider ldap
AuthUserFile /dev/null
AuthName "ldap_auth"
AuthType Basic
AuthLDAPURL ldap_url
AuthLDAPBindDN ldap_dn
AuthLDAPBindPassword ldap_pass
Require ldap-group ldap_group

</Directory>
</VirtualHost>

/etc/httpd/conf.d/test2.conf:

<VirtualHost *:80>
  Servername server_name
  DocumentRoot /var/www/html/test2

  <Directory "/var/www/html/test2">
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

这是我当前httpd.conf文件的相关信息:

ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache

<Directory />
AllowOverride none
Require all denied
</Directory>

<Directory "/var/www">
AllowOverride None
Require all granted
</Directory>

<IfModule dir_module>
DirectoryIndex index.html
</IfModule>

IncludeOptional conf.d/*.conf

但它始终要求对test1和test2进行身份验证,对于test2,我甚至无法在登录后加载内容(test1加载正常)。

1 个答案:

答案 0 :(得分:0)

最后通过使用 Alias 指令实现,所以:

<强> /etc/httpd/conf.d/test1.conf:

<VirtualHost *:80>
Servername server_name
DocumentRoot /var/www/html/test1

Alias /test1 /var/www/html/test1
<Directory "/var/www/html/test1">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all

#LDAP
SetHandler php-script
Require all denied
AuthBasicProvider ldap
AuthUserFile /dev/null
AuthName "ldap_auth"
AuthType Basic
AuthLDAPURL ldap_url
AuthLDAPBindDN ldap_dn
AuthLDAPBindPassword ldap_pass
Require ldap-group ldap_group

</Directory>
</VirtualHost>

<强> /etc/httpd/conf.d/test2.conf:

<VirtualHost *:80>
Servername server_name
DocumentRoot /var/www/html/test2

Alias /test2 /var/www/html/test2
<Directory "/var/www/html/test2">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all