質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

Apache

Apacheは、Apache HTTP Serverの略で、最も人気の高いWebサーバソフトウェアの一つです。安定性が高いオープンソースソフトウェアとして商用サイトから自宅サーバまで、多くのプラットフォーム向けに開発・配布されています。サーバーソフトウェアの不具合(NCSA httpd)を修正するパッチ(a patch)を集積、一つ独立したソフトウェアとして開発されました。

Q&A

解決済

1回答

39527閲覧

apacheでDocumentRoot以外のアクセス方法について

nob777

総合スコア112

CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

Apache

Apacheは、Apache HTTP Serverの略で、最も人気の高いWebサーバソフトウェアの一つです。安定性が高いオープンソースソフトウェアとして商用サイトから自宅サーバまで、多くのプラットフォーム向けに開発・配布されています。サーバーソフトウェアの不具合(NCSA httpd)を修正するパッチ(a patch)を集積、一つ独立したソフトウェアとして開発されました。

1グッド

2クリップ

投稿2016/03/06 07:18

編集2016/03/06 08:47

centos7 + apache環境にて、Aliasディレクティブを利用し、DocumentRoot以外に配置している
index.htmlを参照させようとしました。
しかし、403および404エラーが発生し、参照できません。

selinuxを解除し、どのユーザでも参照可能な/tmp配下にindex.htmlを配置しても
参照できません。

・apacheのエラーメッセージ(403エラー発生時のみ出力されます。404エラー時はエラーメッセージ無し。)
[Sun Mar 06 15:51:38.310390 2016] [autoindex:error] [pid 2989] [client 10.0.2.2:63300] AH01276: Cannot serve directory /tmp/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive

・httpd.confの抜粋
(httpd.confのコメント、空行を抜いた全行も最後に記載しておきます)

httpd.conf

1<Directory /> 2 AllowOverride none 3 Require all granted 4</Directory> 5 6DocumentRoot "/var/www/html" 7 8<IfModule dir_module> 9 DirectoryIndex index.html index.php 10</IfModule> 11 12<IfModule alias_module> 13 Alias /tmp /tmp 14 <Directory /tmp> 15 Require all granted 16 </Directory> 17 ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" 18</IfModule> 19

下記は403エラーとなるURLです。
http://localhost/tmp/

下記は404エラーとなるURLです。
http://localhost/tmp/index.html

・/tmp配下にはindex.htmlが644で配置してあります
ls -l /tmp/index.html
-rw-r--r--. 1 root root 28 3月 6 15:07 /tmp/index.html

■質問事項
どのようにすれば参照できるのでしょうか?

■環境情報
・OSバージョン
CentOS Linux release 7.2.1511 (Core)

・apacheバージョン
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 19 2015 21:43:13

■参考情報

httpd.conf

1ServerRoot "/etc/httpd" 2Listen 80 3LoadModule proxy_module modules/mod_proxy.so 4LoadModule proxy_ajp_module modules/mod_proxy_ajp.so 5Include conf.modules.d/*.conf 6User apache 7Group apache 8ServerAdmin root@localhost 9<Directory /> 10 AllowOverride none 11 Require all granted 12</Directory> 13DocumentRoot "/var/www/html" 14<Directory "/var/www"> 15 AllowOverride None 16 Require all granted 17</Directory> 18<Directory "/var/www/html"> 19 Options Indexes FollowSymLinks 20 AllowOverride None 21 Require all granted 22</Directory> 23<IfModule dir_module> 24 DirectoryIndex index.html index.php 25</IfModule> 26<Files ".ht*"> 27 Require all denied 28</Files> 29ErrorLog "logs/error_log" 30LogLevel warn 31<IfModule log_config_module> 32 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined 33 LogFormat "%h %l %u %t \"%r\" %>s %b" common 34 <IfModule logio_module> 35 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio 36 </IfModule> 37 CustomLog "logs/access_log" combined 38</IfModule> 39<IfModule alias_module> 40 Alias /tmp /tmp 41 <Directory /tmp> 42 Require all granted 43 </Directory> 44 ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" 45</IfModule> 46<Directory "/var/www/cgi-bin"> 47 AllowOverride None 48 Options None 49 Require all granted 50</Directory> 51<IfModule mime_module> 52 TypesConfig /etc/mime.types 53 AddType application/x-compress .Z 54 AddType application/x-gzip .gz .tgz 55 AddType text/html .shtml 56 AddOutputFilter INCLUDES .shtml 57</IfModule> 58AddDefaultCharset UTF-8 59<IfModule mime_magic_module> 60 MIMEMagicFile conf/magic 61</IfModule> 62EnableSendfile on 63IncludeOptional conf.d/*.conf

■追加情報
apacheをデバッグレベルで出力したログです。

http://localhost/tmp/
[Sun Mar 06 17:26:32.087141 2016] [authz_core:debug] [pid 5571] mod_authz_core.c(809): [client 10.0.2.2:64052] AH01626: authorization result of Require all granted: granted
[Sun Mar 06 17:26:32.087353 2016] [authz_core:debug] [pid 5571] mod_authz_core.c(809): [client 10.0.2.2:64052] AH01626: authorization result of <RequireAny>: granted
[Sun Mar 06 17:26:32.087519 2016] [authz_core:debug] [pid 5571] mod_authz_core.c(809): [client 10.0.2.2:64052] AH01626: authorization result of Require all granted: granted
[Sun Mar 06 17:26:32.087534 2016] [authz_core:debug] [pid 5571] mod_authz_core.c(809): [client 10.0.2.2:64052] AH01626: authorization result of <RequireAny>: granted
[Sun Mar 06 17:26:32.087628 2016] [authz_core:debug] [pid 5571] mod_authz_core.c(809): [client 10.0.2.2:64052] AH01626: authorization result of Require all granted: granted
[Sun Mar 06 17:26:32.087637 2016] [authz_core:debug] [pid 5571] mod_authz_core.c(809): [client 10.0.2.2:64052] AH01626: authorization result of <RequireAny>: granted
[Sun Mar 06 17:26:32.087890 2016] [autoindex:error] [pid 5571] [client 10.0.2.2:64052] AH01276: Cannot serve directory /tmp/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive

http://localhost/tmp/index.html
[Sun Mar 06 17:28:06.290017 2016] [authz_core:debug] [pid 5570] mod_authz_core.c(809): [client 10.0.2.2:64062] AH01626: authorization result of Require all granted: granted
[Sun Mar 06 17:28:06.290412 2016] [authz_core:debug] [pid 5570] mod_authz_core.c(809): [client 10.0.2.2:64062] AH01626: authorization result of <RequireAny>: granted
[Sun Mar 06 17:28:06.290631 2016] [core:info] [pid 5570] [client 10.0.2.2:64062] AH00128: File does not exist: /tmp/index.html

また、切り分けのために下記のように/var/www/html内でAliasを使用した際のログも記載します。(正常アクセス可能)
Alias /nob /var/www/html/nob777↲
<Directory /var/www/html/nob777>↲
Require all granted↲
</Directory>

http://localhost/nob/index.html
[Sun Mar 06 17:30:59.392574 2016] [authz_core:debug] [pid 6330] mod_authz_core.c(809): [client 10.0.2.2:64067] AH01626: authorization result of Require all granted: granted
[Sun Mar 06 17:30:59.392697 2016] [authz_core:debug] [pid 6330] mod_authz_core.c(809): [client 10.0.2.2:64067] AH01626: authorization result of <RequireAny>: granted
[Sun Mar 06 17:30:59.892143 2016] [proxy:debug] [pid 6574] proxy_util.c(1843): AH00925: initializing worker proxy:reverse shared
[Sun Mar 06 17:30:59.892278 2016] [proxy:debug] [pid 6574] proxy_util.c(1885): AH00927: initializing worker proxy:reverse local
[Sun Mar 06 17:30:59.892350 2016] [proxy:debug] [pid 6574] proxy_util.c(1936): AH00931: initialized single connection worker in child 6574 for (*)

以上、よろしくお願いいたします。

退会済みユーザー👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

自己解決しました。

下記のように/usr/local配下であればエラーは発生せず、正常にア
クセスできました。

Alias /usr /usr/local↲ <Directory /usr/local>↲ AllowOverride None↲ Require all granted↲ </Directory>↲

※最初から/usr/localで確認しておけばよかったです・・・

推測になりますが、/tmp配下はOS的に制御を掛けているような気が
します。
ただ、元々/tmp配下へのAliasは、権限回りの懸念を排除するために
行った検証目的でした。(が、今後は避けるべきですね・・・)

本件の問題自体は解消されたので、これ以上の深追いはやめておき
ます。

投稿2016/03/06 10:16

nob777

総合スコア112

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問