Skip to content

Commit

Permalink
Merge pull request #294 from oithxs/chore/add-nginx-container
Browse files Browse the repository at this point in the history
開発環境にnginxコンテナを導入・php artisan serve コマンドでの開発鯖を起動しない
  • Loading branch information
Nave-wata authored Oct 3, 2023
2 parents d7b0a20 + abe9ef2 commit 7dafadf
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 9 deletions.
15 changes: 13 additions & 2 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
version: "3.8"
services:
hira-chan_nginx:
image: hira-chan:nginx-1.0.0
container_name: hira-chan_nginx
build:
context: .
dockerfile: ./docker/nginx/Dockerfile
ports:
- 80:80
depends_on:
- hira-chan_app
tty: true

hira-chan_app:
image: hira-chan:app-2.0.0
image: hira-chan:app-2.1.0
container_name: hira-chan_app
build:
context: .
Expand All @@ -10,7 +22,6 @@ services:
volumes:
- .:/usr/src/app
ports:
- 80:80
- 5173:5173
depends_on:
- hira-chan_echo-server
Expand Down
2 changes: 2 additions & 0 deletions docker/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ RUN \
unzip \
wget \
zlib1g-dev \
php-fpm \
php-ctype \
php-curl \
php-dom \
Expand Down Expand Up @@ -65,6 +66,7 @@ COPY --from=composer:2.5.5 /usr/bin/composer /usr/bin/composer

# 設定ファイルをコピー
COPY ./docker/app/php/php.ini /etc/php/8.1/cli/php.ini
COPY ./docker/app/php/www.conf /etc/php/8.1/fpm/pool.d/www.conf
COPY ./docker/app/postfix/main.cf /etc/postfix/main.cf

# コンテナ作成時に実行するスクリプトをコピー
Expand Down
8 changes: 1 addition & 7 deletions docker/app/bin/containerStart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fi
# 各種サービス起動
sudo su <<EOF
service postfix start
service php8.1-fpm start
EOF

# 使用できないセッションの削除
Expand All @@ -33,7 +34,6 @@ screen -wipe
# セッションの作成
screen -dmS vite
screen -dmS queue
screen -dmS serve

# vite セッションで vite を用いた自動ビルドを動作
screen -S vite -X stuff ' \
Expand All @@ -47,10 +47,4 @@ screen -S queue -X stuff ' \
php artisan queue:work \
\n'

# serve セッションで Laravel のサーバーを動作
screen -S serve -X stuff ' \
cd "$WORKDIR"; \
php artisan serve --host 0.0.0.0 --port 80 \
\n'

sleep infinity
15 changes: 15 additions & 0 deletions docker/app/php/www.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[www]
user = www-data
group = www-data

listen = hira-chan_app:9000
listen.owner = www-data
listen.group = www-data

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

request_terminate_timeout = 3600
6 changes: 6 additions & 0 deletions docker/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM nginx:1.24.0

ENV TZ="Asia/Tokyo"
ENV LANG="ja_JP.UTF-8"

COPY ./docker/nginx/conf.d /etc/nginx/conf.d
39 changes: 39 additions & 0 deletions docker/nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
server {
listen 80;
listen [::]:80;
root /usr/src/app;

add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";

index index.php index.html;

charset utf-8;

location = /favicon.ico {
access_log off;
log_not_found off;
}
location = /robots.txt {
access_log off;
log_not_found off;
}

error_page 404 /index.php;

location / {
try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
root /usr/src/app/public;
fastcgi_pass hira-chan_app:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.(?!well-known).* {
deny all;
}
}

0 comments on commit 7dafadf

Please sign in to comment.