Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Apache从外部IP访问时,密码保护目录_Apache_Passwords_Directory_Local - Fatal编程技术网

使用Apache从外部IP访问时,密码保护目录

使用Apache从外部IP访问时,密码保护目录,apache,passwords,directory,local,Apache,Passwords,Directory,Local,目前,我的主目录和子目录都有密码保护,但是我想只在从外部IP地址连接时需要密码保护,而在从本地子网连接时不需要密码保护 当前/etc/apache2/sites available/default如下所示: <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www <Directory /> Op

目前,我的主目录和子目录都有密码保护,但是我想只在从外部IP地址连接时需要密码保护,而在从本地子网连接时不需要密码保护

当前
/etc/apache2/sites available/default
如下所示:

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

    <Location / >
       AuthType Digest
       AuthName "intranet"
       AuthDigestDomain /var/www/ http://10.1.2.2

       AuthDigestProvider file
       AuthUserFile /etc/apache2/passwords
       Require user user1
       SetEnv R_ENV "/var/www"
   </Location>

   <Location /dir1>
        AuthType Digest
        AuthName "dir"
        AuthDigestDomain /var/www/dir1/ http://10.1.2.2/dir1

        AuthDigestProvider file
        AuthUserFile /etc/apache2/passwords
        Require user user2
        SetEnv R_ENV "/var/www/dir1"
    </Location>

    <Location /dir2>
        AuthType Digest
        AuthName "dir"
        AuthDigestDomain /var/www/ http://10.1.2.2/dir2

        AuthDigestProvider file
        AuthUserFile /etc/apache2/passwords
        Require user user2
        SetEnv R_ENV "/var/www/dir2"
    </Location>

</VirtualHost>

服务器管理员webmaster@localhost
DocumentRoot/var/www
选项如下符号链接
不允许超限
选项索引跟随符号链接多视图
不允许超限
命令允许,拒绝
通融
ScriptAlias/cgi-bin//usr/lib/cgi-bin/
不允许超限
选项+执行CGI-多视图+符号链接所有者匹配
命令允许,拒绝
通融
ErrorLog${APACHE_LOG_DIR}/error.LOG
#可能的值包括:调试、信息、通知、警告、错误、临界值、,
#警惕,埃默格。
日志级别警告
CustomLog${APACHE\u LOG\u DIR}/access.LOG组合
别名/doc/“/usr/share/doc/”
选项索引多视图跟随符号链接
不允许超限
命令拒绝,允许
全盘否定
允许从127.0.0.0/255.0.0.0::1/128开始
AuthType摘要
AuthName“内部网”
AuthDigestDomain/var/www/http://10.1.2.2
AuthDigestProvider文件
AuthUserFile/etc/apache2/passwords
需要用户user1
SetEnv R_ENV“/var/www”
AuthType摘要
AuthName“dir”
AuthDigestDomain/var/www/dir1/http://10.1.2.2/dir1
AuthDigestProvider文件
AuthUserFile/etc/apache2/passwords
需要用户user2
SetEnv R_ENV“/var/www/dir1”
AuthType摘要
AuthName“dir”
AuthDigestDomain/var/www/http://10.1.2.2/dir2
AuthDigestProvider文件
AuthUserFile/etc/apache2/passwords
需要用户user2
SetEnv R_ENV“/var/www/dir2”

我在上有过一点收获,但无法理解如何使用它实现密码保护。

一点搜索就发现了这一点

基本上改变了这一点:

<Location / >
   AuthType Digest
   AuthName "intranet"
   AuthDigestDomain /var/www/ http://10.1.2.2

   AuthDigestProvider file
   AuthUserFile /etc/apache2/passwords
   Require user user1
   SetEnv R_ENV "/var/www"
</Location>

AuthType摘要
AuthName“内部网”
AuthDigestDomain/var/www/http://10.1.2.2
AuthDigestProvider文件
AuthUserFile/etc/apache2/passwords
需要用户user1
SetEnv R_ENV“/var/www”
为此:

<Location />
    Order deny,allow
    Deny from all
    AuthType Digest
    AuthName "intranet"
    AuthDigestDomain /var/www/ http://10.1.2.2

    AuthDigestProvider file
    AuthUserFile /etc/apache2/passwords
    Require valid-user
    SetEnv R_ENV "/var/www"
    Allow from 10.1.2.0/24
    Satisfy Any
</Location>

命令拒绝,允许
全盘否定
AuthType摘要
AuthName“内部网”
AuthDigestDomain/var/www/http://10.1.2.2
AuthDigestProvider文件
AuthUserFile/etc/apache2/passwords
需要有效用户
SetEnv R_ENV“/var/www”
允许从10.1.2.0/24开始
满足任何
经过测试,一切运行顺利