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

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

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

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

Q&A

解決済

1回答

2356閲覧

81番ポートでdockerコンテナのapacheにアクセスするとphpが実行されずファイルダウンロードになる

bakaemon

総合スコア35

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

0グッド

1クリップ

投稿2019/01/06 14:59

編集2019/01/06 15:06

docker初心者です。
81番ポートでapacheコンテナを動かそうとしているのですが、http://xxx.xxx.xxx:81でアクセスすると、以下の内容のファイルがダウンロードされてしまいます。
(Laravelのオートローダーのようです。)

<?php /** * Laravel - A PHP Framework For Web Artisans * * @package Laravel * @author Taylor Otwell <taylor@laravel.com> */ define('LARAVEL_START', microtime(true)); /* |-------------------------------------------------------------------------- | Register The Auto Loader |-------------------------------------------------------------------------- | | Composer provides a convenient, automatically generated class loader for | our application. We just need to utilize it! We'll simply require it | into the script here so that we don't have to worry about manual | loading any of our classes later on. It feels great to relax. | */ require __DIR__.'/../vendor/autoload.php'; /* |-------------------------------------------------------------------------- | Turn On The Lights |-------------------------------------------------------------------------- | | We need to illuminate PHP development, so let us turn on the lights. | This bootstraps the framework and gets it ready for use, then it | will load up this application so that we can run it and send | the responses back to the browser and delight our users. | */ $app = require_once __DIR__.'/../bootstrap/app.php'; /* |-------------------------------------------------------------------------- | Run The Application |-------------------------------------------------------------------------- | | Once we have the application, we can handle the incoming request | through the kernel, and send the associated response back to | the client's browser allowing them to enjoy the creative | and wonderful application we have prepared for them. | */ $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); $response = $kernel->handle( $request = Illuminate\Http\Request::capture() ); $response->send(); $kernel->terminate($request, $response);

docker ps の結果は以下です。

[root@os3-374-20202 httpd]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bb54e119662c 75d6aabd27d6 "/sbin/init" 29 minutes ago Up 29 minutes 80/tcp, 0.0.0.0:81->81/tcp ga_k8s-test1 b5b9a182ca27 laradock_beanstalkd "/usr/bin/beanstalkd" 3 hours ago Up 3 hours 0.0.0.0:11300->11300/tcp laradock_beanstalkd_1 54de35884935 laradock_nginx "/bin/bash /opt/star…" 3 hours ago Up 3 hours 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp laradock_nginx_1 fce505b944c5 laradock_php-fpm "docker-php-entrypoi…" 3 hours ago Up 3 hours 9000/tcp laradock_php-fpm_1 cc2c20deff49 laradock_workspace "/sbin/my_init" 3 hours ago Up 3 hours 0.0.0.0:2222->22/tcp laradock_workspace_1 5bb8870c05d4 laradock_mysql "docker-entrypoint.s…" 3 hours ago Up 3 hours 0.0.0.0:3306->3306/tcp, 33060/tcp laradock_mysql_1 23968ee56bc4 docker:dind "dockerd-entrypoint.…" 3 hours ago Up 3 hours 2375/tcp laradock_docker-in-docker_1 ef4e1aa9c143 laradock_redis "docker-entrypoint.s…" 3 hours ago Up 3 hours 0.0.0.0:6379->6379/tcp laradock_redis_1 ※一番上の ga_k8s-test1 が問題のコンテナです。

ga-k8s-test1 の中の /etc/httpd/conf.d/php.conf の記述が以下です。

[root@bb54e119662c conf.d]# cat php.conf # # The following lines prevent .user.ini files from being viewed by Web clients. # <Files ".user.ini"> <IfModule mod_authz_core.c> Require all denied </IfModule> <IfModule !mod_authz_core.c> Order allow,deny Deny from all Satisfy All </IfModule> </Files> # # Allow php to handle Multiviews # AddType text/html .php # # Add index.php to the list of files that will be served as directory # indexes. # DirectoryIndex index.php # mod_php options <IfModule mod_php7.c> # # Cause the PHP interpreter to handle files with a .php extension. # <FilesMatch .(php|phar)$> SetHandler application/x-httpd-php </FilesMatch> # # Uncomment the following lines to allow PHP to pretty-print .phps # files as PHP source code: # #<FilesMatch .phps$> # SetHandler application/x-httpd-php-source #</FilesMatch> # # Apache specific PHP configuration options # those can be override in each configured vhost # php_value session.save_handler "files" php_value session.save_path "/var/lib/php/session" php_value soap.wsdl_cache_dir "/var/lib/php/wsdlcache" #php_value opcache.file_cache "/var/lib/php/opcache" </IfModule>

ホスト側でもコンテナ側でも、curl http://localhost:81 を実行するとちゃんとhtmlファイルが返ってきます。
どうしてブラウザから http://xxx.xxx.xxx:81 (xxx.xxx.xxxはドメイン名) を叩くと、ファイルのダウンロードになってしまうのでしょうか。

追記

なぜか edge からだと正常にアクセスできました。
chromeだと上記の事象になります。
chromeに何か原因があるんでしょうか?

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

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

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

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

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

guest

回答1

0

ベストアンサー

chromeのキャッシュではないでしょうか。

https://fujishinko.exblog.jp/9321978/
ちょっと古い記事ですが。

キャッシュでなかったとしても、dockerの問題というよりはApacheの設定の問題とかのような。

投稿2019/01/09 05:25

t_obara

総合スコア5488

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

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

bakaemon

2019/01/09 11:52 編集

ご指摘を受けて、今日履歴とか諸々削除してもう一回コンテナを起動したら今回はうまく表示されました。 もしかすると、chromeのキャッシュっURLとその結果でキャッシュしてるんですかね。 ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問