Create a basic PHP and nginx container pair, mounting their local working directory.
docker-compose.yml
version: '3'
services:
nginx:
image: nginx:stable-alpine
ports:
- "8080:80"
volumes:
- .:/var/www/html
- .docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
php:
image: php:7.4-fpm
volumes:
- .:/var/www/html
.docker/nginx/default.conf
server {
listen 80 default_server;
root /var/www/html;
index index.html index.htm index.php;
charset utf-8;
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; }
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ ^/.+\.php(/|$) {
fastcgi_pass php:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_read_timeout 3600;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
error_page 404 /index.php;
location ~ /\.ht {
deny all;
}
}