금지된 Apache 디렉토리의 단일 파일에 대해 기본 인증을 사용하는 방법은 무엇입니까?

금지된 Apache 디렉토리의 단일 파일에 대해 기본 인증을 사용하는 방법은 무엇입니까?

금지된 디렉토리의 단일 파일에 대한 액세스를 허용하고 싶습니다.

이것은 작동하지 않았습니다.

<VirtualHost 10.10.10.10:80>
  ServerName example.com

  DocumentRoot /var/www/html

  <Directory /var/www/html>
    Options FollowSymLinks
    AllowOverride None
    order allow,deny
    allow from all
  </Directory>

  # disallow the admin directory: 
  <Directory /var/www/html/admin>
    order allow,deny
    deny from all
  </Directory>

  # but allow this single file:: 
  <Files      /var/www/html/admin/allowed.php>
      AuthType basic
      AuthName "private area"
      AuthUserFile /home/webroot/.htusers
      Require user admin1
  </Files>

  ...
</VirtualHost>

방문하면 디렉토리 http://example.com/admin/allowed.php의 Forbidden 메시지가 표시되지만 http://example.com/admin/기본 인증의 브라우저 로그인 팝업은 표시되지 않으므로 기본 인증이 파일에서 작동하지 않습니다. allowed.php에 대해 어떻게 예외를 만들 수 있나요?

가능하지 않다면 다른 Files 지시어에 금지된 파일을 모두 나열할 수 있을까요?

admin/에 이 가상 호스트에서 금지되어야 하는 user.php 및 admin.php도 포함되어 있다고 가정해 보겠습니다.

편집하다:또한 Ignacio의 답변에 대한 조언을 따르려고 다음 수정을 시도했지만 '금지됨'과 같은 결과가 나왔습니다.

  ...

  # disallow the admin directory: 
  <Directory /var/www/html/admin>
    order allow,deny
    deny from all
  </Directory>

  # but allow this single file:: 
  <Files      /var/www/html/admin/allowed.php>
      order allow,deny
      allow from all
      AuthType basic
      AuthName "private area"
      AuthUserFile /home/webroot/.htusers
      Require user admin1
      satisfy all
  </Files>
  ...

답변1

이 시도:

<Directory /var/www/html/admin>
  <Files allowed.php>
    AuthType basic
    AuthName "private area"
    AuthUserFile /home/webroot/.htusers
    Require user admin1
  </Files>
  order allow,deny
  deny from all
  satisfy any
</Directory>

디렉터리 내에 중첩된 파일은 해당 디렉터리에만 적용되므로 코드 블록이 보다 논리적으로 구성되며 '모두 만족'을 사용하면 계획대로 병합할 수 있을 것입니다. 실제로 필요한지 확실하지 않으므로 만족 줄을 사용하거나 사용하지 않고 시도해보십시오.

답변2

<Files xxx>솔루션이 실제로 잘 작동하는지 잘 모르겠습니다 .문서 페이지 필요에는 적용되지 않는다고 명시하고 있습니다.Files

Context:    directory, .htaccess

대신 Apache 문서에서 제안하는 것은 파일에 대해 별도의 디렉터리를 만드는 것입니다.

하위 디렉터리의 컨트롤 제거

다음 예에서는 Satisfy 지시문을 사용하여 보호된 디렉터리의 하위 디렉터리에서 액세스 제어를 비활성화하는 방법을 보여줍니다. 이 기술은 mod_authz_host에 의해 부과된 모든 액세스 제어도 비활성화되므로 주의해서 사용해야 합니다.

<Directory /path/to/protected/>
    Require user david
</Directory>
<Directory /path/to/protected/unprotected>
    # All access controls and authentication are disabled
    # in this directory
    Satisfy Any
    Allow from all
</Directory>

관련 정보