質問編集履歴

4

再現コマンドの追記

2022/09/16 02:37

投稿

SatoKenta
SatoKenta

スコア38

test CHANGED
File without changes
test CHANGED
@@ -56,3 +56,33 @@
56
56
  ### 質問
57
57
 
58
58
  なぜDocumentRoot外のディレクトリがApacheの動作に影響してしまうのかが理解できません。
59
+
60
+
61
+ ### 9/16 追記
62
+
63
+ Dockerコンテナで現象を再現するためのコマンドを作りました。以下の通りです。
64
+
65
+ ```
66
+ # Pull and run httpd docker image
67
+ docker run --rm -d --name test_httpd -p 4000:80 docker.io/httpd:2.4.51
68
+
69
+ # Append rewrite rule to httpd.conf
70
+ docker cp test_httpd:/usr/local/apache2/conf/httpd.conf ./
71
+ echo $'LoadModule rewrite_module modules/mod_rewrite.so\nRewriteEngine on\nRewriteRule .* /test/sorry.html' >> httpd.conf
72
+ docker cp ./httpd.conf test_httpd:/usr/local/apache2/conf/httpd.conf
73
+
74
+ # Create test HTML page
75
+ docker exec test_httpd sh -c "mkdir /usr/local/apache2/htdocs/test && echo Test page > /usr/local/apache2/htdocs/test/sorry.html"
76
+ docker restart test_httpd
77
+
78
+ # This curl command works as expected. (says "Test page" with status 200)
79
+ curl http://localhost:4000/foo/bar
80
+
81
+ # After creating `/test` directory in my root directory in container, apache returns "403 Forbidden".
82
+ docker exec test_httpd sh -c "mkdir /test"
83
+ curl http://localhost:4000/foo/bar
84
+ docker stop test_httpd
85
+ ```
86
+
87
+ Apache Bugzillaにも投稿してみました。
88
+ https://bz.apache.org/bugzilla/show_bug.cgi?id=66267

3

誤記修正

2022/09/16 01:40

投稿

SatoKenta
SatoKenta

スコア38

test CHANGED
File without changes
test CHANGED
@@ -44,7 +44,7 @@
44
44
  #### 5. curlの応答が403になってしまいます。
45
45
 
46
46
  ```
47
- $ curl http://localhost/aaaaa`
47
+ $ curl http://localhost/aaaaa
48
48
  <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
49
49
  <html><head>
50
50
  <title>403 Forbidden</title>

2

誤記修正

2022/09/16 01:33

投稿

SatoKenta
SatoKenta

スコア38

test CHANGED
File without changes
test CHANGED
@@ -21,7 +21,7 @@
21
21
  この後、`systemctl restart` または `docker restart` で定義を読み込みます。
22
22
 
23
23
 
24
- #### 2. DocumentRootに上記ファイルを作成します。
24
+ #### 2. DocumentRootにRewrite先のファイルを作成します。
25
25
 
26
26
  RHEL版の場合は
27
27
  `$ mkdir /var/www/html/test`

1

誤字修正

2022/09/16 01:32

投稿

SatoKenta
SatoKenta

スコア38

test CHANGED
File without changes
test CHANGED
@@ -16,7 +16,7 @@
16
16
  ```
17
17
  LoadModule rewite_module modules/mod_rewrite.so # RHELの場合は最初から有効なのでdocker版のみ追記
18
18
  RewriteEngine on
19
- RewriteRule .* /test/test/html
19
+ RewriteRule .* /test/index.html
20
20
  ```
21
21
  この後、`systemctl restart` または `docker restart` で定義を読み込みます。
22
22
 
@@ -25,10 +25,10 @@
25
25
 
26
26
  RHEL版の場合は
27
27
  `$ mkdir /var/www/html/test`
28
- `$ echo "Test page" > /var/www/html/test/test.html`
28
+ `$ echo "Test page" > /var/www/html/test/index.html`
29
29
  Dockerの場合は
30
30
  `$ mkdir /usr/local/apache2/htdocs/test`
31
- `$ echo "Test page" > /usr/local/apache2/htdocs/test/test.html`
31
+ `$ echo "Test page" > /usr/local/apache2/htdocs/test/index.html`
32
32
 
33
33
  #### 3. 当然ですが、アクセスするとRewrite先の上記ページが見えます。
34
34