Apache 공통 문서 루트, 다양한 가상 호스트, 다양한 액세스 가능 파일

Apache 공통 문서 루트, 다양한 가상 호스트, 다양한 액세스 가능 파일

LFCE 시험을 보고 질문을 했습니다. 이 질문에는 apache2와 2개의 가상 호스트를 설치해야 합니다. site1.example.com 및 site2.example.com. 두 개의 가상 호스트공유 문서 루트 디렉터리 /var/www/html/.. 또한 문서 루트에 2개의 다른 파일이 필요합니다. test_page1.html 및 test_page2.html과 요청된 파일 test_page1.html은 site1.example.com 가상 호스트에서만 액세스할 수 있는 반면, test_page2.html은 site2.example.com에서만 액세스할 수 있습니다.

내 질문은 test_page1.html이 vhost 2에서 액세스할 수 없도록 하고 그 반대의 경우도 마찬가지인지 확인하는 방법입니다(동일한 문서 루트를 공유하는 경우).

가상 호스트 1

<VirtualHost *:80>
ServerName site1.example.com
DocumentRoot /var/www/html/
<Directory /var/www/html/> 
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

가상 호스트 2

<VirtualHost *:80>
ServerName site2.example.com
DocumentRoot /var/www/html/
<Directory /var/www/html/> 
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

답변1

나중에 참고할 수 있도록 내 질문에 답변하겠습니다. 결합하면 가능해요장소막힌,일반적인 표현그리고서버 변수.

새 프로필 만들기

nano /etc/apache2/sites-available/secure.conf

다음에 추가:

<Location /test_page1.html>
    <If "!(%{SERVER_NAME} -strmatch 'site1.example.com*')">
    Require all denied
    </If>
</Location>
<Location /test_page2.html>
    <If "!(%{SERVER_NAME} -strmatch 'site2.example.com*')">
    Require all denied
    </If>
</Location>

구성을 활성화하고 Apache를 다시 시작합니다.

 a2ensite secure
 systemctl restart apache2

관련 정보