아파치 가상 호스트 구성 CentOS7

아파치 가상 호스트 구성 CentOS7

내 호스트 컴퓨터는 Windows 7이고 게스트 컴퓨터는 CentOS 7입니다. 저는 Apache를 처음 사용하고 CentOS7에서 VirtualHost를 만들려고 합니다. 저는 StackCommunity에서 많은 문서와 답변을 읽었습니다(아파치 심볼릭 링크)가상 호스트 CentOS7등. 이것이 제가하는 것입니다. 내 파일 구성 /etc/httpd/conf/httpd.conf에 변경 사항이 추가되지 않았습니다 .

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

User apache
Group apache

ServerAdmin root@localhost

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

DocumentRoot "/var/www/html"

<Directory "/var/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory>

<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

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

<Files ".ht*">
Require all denied
</Files>

ErrorLog "logs/error_log"

LogLevel warn

<IfModule log_config_module>
#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""     combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common

<IfModule logio_module>
# You need to enable mod_logio.c to use %I and %O
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio

</IfModule>CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
 ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>

<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>

<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>

AddDefaultCharset UTF-8

<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>

EnableSendfile on
IncludeOptional conf.d/*.conf

/var/www/html다음 내용으로 index.html을 추가했습니다 .

<html>
<title> The library </title>
<body>
<h2> Welcome to our library </h2>
<br /> <hr> <br />
<img width = "600" height = "400" src = "images/library.jpg">
<body/>
</html>

/var/www/html/index.html그런 다음 심볼릭 링크를 만들었습니다./var/www/my_host/my_host.html

ln -s /var/www/html/index.html /var/www/html/my_host.html

다음 단계: 내가 만들고 my_host.conf허용 /etc/httpd/conf.d/합니다.심볼릭 링크:

vim /etc/httpd/conf.d/my_host.conf

<VirtualHost *:80>
ServerName www.my_host.com
ServerAlias *.my_host.com
DocumentRoot /var/www/my_host
<Directory "/var/www/my_host">
Options FollowSymLinks Indexes
AllowOverride All
</Directory>
ErrorLog /var/www/my_host/error_log
LogFormat "%a %v %p %U %m %T" common_new_format
CustomLog /var/www/my_host/custom_log common_new_format
</VirtualHost>

그런 다음 다음 명령으로 Apache를 확인하고 apachectl configtest출력 => 을 얻었습니다 Syntax OK. 이 모든 단계를 완료한 후 httpd를 시작했습니다.

systemctl start httpd

모든 것이 완벽하게 시작되었습니다.

하지만 내 가상 호스트의 error_log에 문제가 있습니다.

AH01276: Cannot serve directory /var/www/my_host/: No matching DirectoryIndex (index.html) found, and server-generated directory index forbidden by Options directive

DirectoryIndex my_host.html내 파일에 추가할 수 있다는 것을 알고 있지만 my_host.conf심볼릭 링크 my_host.html -> ../html/index.html예상대로 작동하지 않나요? FollowSymLinks/var/www/my_host/디렉토리를 허용하는 것만으로도 충분하고 다른 디렉토리를 가리킬 필요가 없다고 생각합니까 DirectoryIndex? 내 질문은: index.html에 심볼릭 링크를 추가한 경우 FollowSymLinks이를 지적하는 것만으로는 충분하지 않은 이유는 무엇입니까?DirectoryIndex

답변1

나는 당신이 심볼릭 링크를 너무 많이 읽고 있다고 생각합니다. 두 경우 모두 호출된 파일에 심볼릭 링크된 파일이 httpd있는지 확인하지 않습니다 . DocumentRoot에 이름이 지정된 파일을 index.html찾습니다 .index.html

FollowSymLinks해당 파일이 존재하고 심볼릭 링크일 때 필요합니다. (실수로 또는 악의적으로 심볼릭 링크 /etc/passwd나 개인 SSH 키가 DocumentRoot에 들어갔다고 상상해 보세요!)

관련 정보