多个网站/ dirs的Apache htpasswd?

时间:2016-06-06 11:46:04

标签: apache .htaccess

我不是100%熟悉htpasswd是如何工作的,但我想知道它是否可行。

我有一台服务器,其中包含一个IP和多个域。我需要密码保护所有这些域,但如果可能只在一个地方。我不想四处走动,为每个网站制作htpasswd。

假设我将所有网站放在/ var / www / {vhost dirs}

是否可能,以及如何以及如何?

1 个答案:

答案 0 :(得分:0)

apache中的虚拟主机配置可以实现单个IP上的多个域。

 E.g I am running few domains on single machine :
   www.internationalworkersday.com
   www.internationallabourday.com
   www.internationlaborday.com
   www.internationalworkersday.org
   www.apnok.com

#Here is virtual host configuration in httpd.conf


# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
<VirtualHost *:80>
    ServerAdmin www.apnok.com
    DocumentRoot /home/ap/
    ServerName www.apnok.com
    ServerAlias apnok.com *.apnok.com
    ErrorLog logs/error_log
    CustomLog logs/access_log common
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin www.internationalworkersday.com
    DocumentRoot /home/iwd/
    ServerName www.internationalworkersday.com
    ServerAlias internationalworkersday.com
    ErrorLog logs/error_log
    CustomLog logs/access_log_iwd common
</VirtualHost>
<VirtualHost *:80>
   # ServerAdmin www.internationallabourday.com
    DocumentRoot /home/ild/
    ServerName www.internationallabourday.com
    ServerAlias internationallabourday.com
   # ErrorLog logs/error_log
    #CustomLog logs/access_log_ild common
    RewriteEngine On
        RewriteCond %{HTTP_HOST} ^internationallabourday\.com [NC]
        RewriteCond %{HTTPS} off
        RewriteRule ^(.*)$ http://www.internationalworkersday.com
#DirectoryIndex index.php index.php.var
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin www.internationallaborday.com
    DocumentRoot /home/ila/
    ServerName www.internationallaborday.com
ServerAlias internationallaborday.com
    ErrorLog logs/error_log
    CustomLog logs/access_log common
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin www.internationalworkersday.org
    DocumentRoot /home/iwd/
    ServerName www.internationalworkersday.org
    ServerAlias internationalworkersday.org
    ErrorLog logs/error_log
    CustomLog logs/access_log_org common
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin www.internationallabourday.org
    DocumentRoot /home/ild/
    ServerName www.internationallabourday.org
    ServerAlias internationallabourday.org
    ErrorLog logs/error_log
    CustomLog logs/access_log_org common
</VirtualHost>