質問編集履歴

1

設定変更後の検証追記。

2016/02/25 08:40

投稿

snic518
snic518

スコア39

test CHANGED
@@ -1 +1 @@
1
- PHP-FPM使用時のPHPファイルへのErrorDocument設定について
1
+ PHP-FPM使用時のPHPファイルへのErrorDocument設定について・検証追記
test CHANGED
@@ -77,3 +77,241 @@
77
77
  ご意見賜れますと幸いです。
78
78
 
79
79
  よろしくお願いいたします。
80
+
81
+
82
+
83
+ ---
84
+
85
+
86
+
87
+ ###【20160225追記】
88
+
89
+
90
+
91
+ 回答いただいた通りに、
92
+
93
+
94
+
95
+
96
+
97
+ この解決方法は、下記のサイトにもありました。
98
+
99
+
100
+
101
+ [Apache 2.4 + PHP-FPM, catching error pages](http://stackoverflow.com/questions/25801695/apache-2-4-php-fpm-catching-error-pages)
102
+
103
+
104
+
105
+
106
+
107
+ 結果、VirtualHostディレクティブの設定は以下のようになりました。
108
+
109
+
110
+
111
+ ※今回の問題に関係ない記述もあると思いますが、念のためすべて掲載しました。
112
+
113
+
114
+
115
+ ```apache
116
+
117
+ <VirtualHost *:80>
118
+
119
+ ServerName hoge.jp
120
+
121
+ DocumentRoot /var/www/html
122
+
123
+
124
+
125
+ ProxyErrorOverride On
126
+
127
+ ErrorDocument 503 /error/503.html
128
+
129
+ ErrorDocument 404 /error/404.html
130
+
131
+ ProxyPassMatch ^(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$1
132
+
133
+ <Directory "/var/www/html">
134
+
135
+ Require all granted
136
+
137
+ Options FollowSymLinks
138
+
139
+
140
+
141
+ # Expires settings
142
+
143
+ ExpiresActive On
144
+
145
+ ExpiresByType text/css "access plus 7 day"
146
+
147
+ ExpiresByType text/javascript "access plus 7 day"
148
+
149
+ ExpiresByType application/x-javascript "access plus 7 day"
150
+
151
+
152
+
153
+ # gzip transrate
154
+
155
+ RewriteEngine On
156
+
157
+ RewriteCond %{HTTP:Accept-Encoding} gzip
158
+
159
+ RewriteCond %{REQUEST_FILENAME} \.js$ [OR]
160
+
161
+ RewriteCond %{REQUEST_FILENAME} \.css$
162
+
163
+ RewriteCond %{REQUEST_FILENAME} !\.gz$
164
+
165
+ RewriteCond %{REQUEST_FILENAME}\.gz -s
166
+
167
+ RewriteRule .+ %{REQUEST_URI}.gz
168
+
169
+
170
+
171
+ <FilesMatch "\.js\.gz$">
172
+
173
+ ForceType application/x-javascript
174
+
175
+ AddEncoding x-gzip .gz
176
+
177
+ </FilesMatch>
178
+
179
+
180
+
181
+ <FilesMatch "\.css\.gz$">
182
+
183
+ ForceType text/css
184
+
185
+ AddEncoding x-gzip .gz
186
+
187
+ </FilesMatch>
188
+
189
+ </Directory>
190
+
191
+ </VirtualHost>
192
+
193
+
194
+
195
+ ```
196
+
197
+
198
+
199
+ その結果、下記のような状態になりました。
200
+
201
+
202
+
203
+ ・PHP以外のファイル … 変化無し。期待通りのエラーページ表示
204
+
205
+ ・PHPファイル … 「File not found.」ではなく、ブラウザのエラーが発生。
206
+
207
+
208
+
209
+ ブラウザのエラーは、chromeの場合下記画像のような表示になります。
210
+
211
+
212
+
213
+ ![エラー表示](d0727480eff7f6b0f3153efaa016fd32.png)
214
+
215
+
216
+
217
+ また、アドバイスいただいた通り、コンソールからcurlでアクセスしてみた場合は、期待通りのページのソースが返ってきました。
218
+
219
+
220
+
221
+ ```SSH
222
+
223
+ $ curl http://127.0.0.1/nofile.php
224
+
225
+ <!doctype html>
226
+
227
+ <html lang="ja">
228
+
229
+ <head>
230
+
231
+ <meta charset="utf-8">
232
+
233
+ <meta name="robots" content="noindex,nofollow">
234
+
235
+ <title>404</title>
236
+
237
+ </head>
238
+
239
+ :
240
+
241
+ :
242
+
243
+ </html>
244
+
245
+ ```
246
+
247
+
248
+
249
+ これは外部の別のサーバーからIPを指定して実行しても同じで、なおかつ外部サーバーから、例えばPHPの下記のようなスクリプトを叩いてみても、期待する404ページHTMLが出力される状態です。
250
+
251
+
252
+
253
+ ```PHP
254
+
255
+ <?php
256
+
257
+ $context = stream_context_create(array(
258
+
259
+ 'http' => array('ignore_errors' => true)
260
+
261
+ ));
262
+
263
+
264
+
265
+ $url = "http://hoge.jp/nofile.php";
266
+
267
+ echo file_get_contents($url, false, $context);
268
+
269
+ ```
270
+
271
+ この時のレスポンスヘッダは以下でした。
272
+
273
+ ```
274
+
275
+ HTTP/1.1 404 Not Found
276
+
277
+ Date: Thu, 25 Feb 2016 08:35:23 GMT
278
+
279
+ Server: Apache
280
+
281
+ Last-Modified: Thu, 25 Feb 2016 08:31:54 GMT
282
+
283
+ Accept-Ranges: bytes
284
+
285
+ Content-Length: 1823
286
+
287
+ X-Frame-Options: SAMEORIGIN
288
+
289
+ X-XSS-Protection: 1; mode=block
290
+
291
+ X-Content-Type-Options: nosniff
292
+
293
+ Connection: close
294
+
295
+ Content-Type: text/html; charset=UTF-8
296
+
297
+ ```
298
+
299
+
300
+
301
+
302
+
303
+ つまり、データの通信上は正しく設定されたものがやり取りされているものの、ブラウザが受信した場合はそれをHTMLページとして表示できていない、という状態なのかなと思います。
304
+
305
+
306
+
307
+ なお、iPhone Safariでアクセスすると、エラーページの表示は「RAWデータをデコードできません」というものになりました。
308
+
309
+
310
+
311
+ Content-Typeはちゃんとtext/htmlになっているみたいなのですが、どうしてこのような状態になっているのか、色々調べてもわかりませんでした。
312
+
313
+
314
+
315
+ 何か問題点があるか、どなたかおわかりになりませんでしょうか。
316
+
317
+ よろしくお願いいたします。