Apache仮想ホストの設定CentOS7

Apache仮想ホストの設定CentOS7

私のホストコンピュータはWindows 7で、ゲストコンピュータはCentOS 7です。私はApacheを初めて使用し、CentOS7でVirtualHostを作成しようとしています。私はStackCommunityで多くの文書と回答を読んでいます(Apacheシンボリックリンク)仮想ホスト 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に入ったと想像してください!)

おすすめ記事