Skip to content

Instantly share code, notes, and snippets.

@Sam-R
Last active April 2, 2020 17:37
Show Gist options
  • Save Sam-R/ae0e89a0e7dc58ba583ace6a0693791b to your computer and use it in GitHub Desktop.
Save Sam-R/ae0e89a0e7dc58ba583ace6a0693791b to your computer and use it in GitHub Desktop.
basic docker-compose setup with nginx and php-fpm container pair

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;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment