2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

出来るだけ最小限でdocker-compose、nginx、phpの環境を作成してみた

Last updated at Posted at 2020-07-05

私は初心者です。間違っていたりもっと良いやり方がありましたら教えていただけるとありがたいです

参考

こちらのリンクにコードを置きました

docker-compose.yml
version: "3"

services:
  web:
    image: nginx
    ports:
      - "8080:80"
    volumes:
      - ./default.conf:/etc/nginx/conf.d/default.conf
      - ./myapp:/var/www/html
    depends_on:
      - php

  php:
    image: php:7-fpm
    volumes:
      - ./myapp:/var/www/html

phpのサービスだけで、/var/www/html にファイルをマウントしたら良いかと思ったのですが、htmlが表示されず(ファイルがなくて404になる)webのサービスの方でも/var/www/htmlマウントしました

default.conf
server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;
    root /var/www/html;

    location / {
        index  index.php index.html;
    }

    location ~ \.php$ {
       fastcgi_pass   php:9000;
       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
       include        fastcgi_params;
    }
}
myapp/index.php
<?php
phpinfo();
docker compose up -d
image.png

以上です。m(_ _)m

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?