From 401d07077809c08a82fcd39460a9072586653a09 Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Thu, 20 Dec 2018 17:32:50 +0100 Subject: [PATCH] Initial commit, seems to work --- .env.sample | 57 +++++++++++++++++++++++++++++++++++++++ .gitignore | 2 ++ docker-compose.yml | 49 +++++++++++++++++++++++++++++++++ docker/php/Dockerfile | 3 +++ nginx/conf.d/default.conf | 3 +++ nginx/nginx.conf | 32 ++++++++++++++++++++++ nginx/sites/default.conf | 33 +++++++++++++++++++++++ 7 files changed, 179 insertions(+) create mode 100644 .env.sample create mode 100644 docker-compose.yml create mode 100644 docker/php/Dockerfile create mode 100644 nginx/conf.d/default.conf create mode 100644 nginx/nginx.conf create mode 100644 nginx/sites/default.conf diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..f9c90c9 --- /dev/null +++ b/.env.sample @@ -0,0 +1,57 @@ +# .env file to set up your LEMP stack with letsencrypt + +# +# Network name +# +# Your container app must use a network conencted to your webproxy +# https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion +# +NETWORK=webproxy + + +# +# Database Container configuration +# We recommend MySQL or MariaDB - please update docker-compose file if needed. +# +CONTAINER_DB_NAME=db + +# Path to store your database +#DB_PATH=/path/to/your/local/database/folder +DB_PATH=./data/db + +# Root password for your database +MYSQL_ROOT_PASSWORD=root_password + +# Database name, user and password for your wordpress +MYSQL_DATABASE=database_name +MYSQL_USER=user_name +MYSQL_PASSWORD=user_password + + +# +# PHP Settings +# +CONTAINER_PHP_NAME=php + + +# +# Webroot configuration +# +#WEBROOT_PATH=/path/to/your/webroot +WEBROOT_PATH=./data/www + + +# +# NGINX Settings +# +CONTAINER_NGINX_NAME=nginx +NGINX_PORT=8081 + +# +# Host +# +# Your domain (or domains) +VIRTUAL_HOST=domain1.com,www.domain1.com +LETSENCRYPT_HOST=domain1.com,www.domain1.com +# Your email for Let's Encrypt register +LETSENCRYPT_EMAIL=your_email@domain.com diff --git a/.gitignore b/.gitignore index 9ebd30b..54ef34a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ !.vscode/launch.json !.vscode/extensions.json +# ---> Production Config File +.env diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b794260 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,49 @@ +version: '3' + +services: + db: + container_name: ${CONTAINER_DB_NAME} + image: mariadb:latest + restart: unless-stopped + volumes: + - ${DB_PATH}:/var/lib/mysql + environment: + MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} + MYSQL_DATABASE: ${MYSQL_DATABASE} + MYSQL_USER: ${MYSQL_USER} + MYSQL_PASSWORD: ${MYSQL_PASSWORD} + + php-fpm: + container_name: ${CONTAINER_PHP_NAME} + #image: php:7-fpm + build: docker/php + restart: unless-stopped + volumes: + - ${WEBROOT_PATH}:/var/www + links: + - db + + nginx: + container_name: ${CONTAINER_NGINX_NAME} + image: nginx:stable + volumes: + - ${WEBROOT_PATH}:/var/www + - ./nginx/nginx.conf:/etc/nginx/nginx.conf + - ./nginx/sites/:/etc/nginx/sites-enabled + - ./nginx/conf.d/:/etc/nginx/conf.d + depends_on: + - php-fpm + ports: + - "${NGINX_PORT}:80" + links: + - php-fpm + + environment: + VIRTUAL_HOST: ${VIRTUAL_HOST} + LETSENCRYPT_HOST: ${LETSENCRYPT_HOST} + LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL} + +networks: + default: + external: + name: ${NETWORK} diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile new file mode 100644 index 0000000..382a09f --- /dev/null +++ b/docker/php/Dockerfile @@ -0,0 +1,3 @@ +FROM php:7-fpm + +RUN docker-php-ext-install pdo_mysql diff --git a/nginx/conf.d/default.conf b/nginx/conf.d/default.conf new file mode 100644 index 0000000..0206580 --- /dev/null +++ b/nginx/conf.d/default.conf @@ -0,0 +1,3 @@ +upstream php-upstream { + server php-fpm:9000; +} diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..c47f95f --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,32 @@ +user nginx; +worker_processes 4; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + #gzip on; + + include /etc/nginx/conf.d/*.conf; + include /etc/nginx/sites-enabled/*.conf; +} diff --git a/nginx/sites/default.conf b/nginx/sites/default.conf new file mode 100644 index 0000000..fe990a8 --- /dev/null +++ b/nginx/sites/default.conf @@ -0,0 +1,33 @@ +server { + listen 80 default_server; + listen [::]:80 default_server; + + server_name localhost; + root /var/www; + index index.php index.html index.htm; + + location / { + try_files $uri $uri/ /index.php$is_args$args; + } + + location ~ \.php$ { + try_files $uri /index.php =404; + fastcgi_pass php-upstream; + fastcgi_index index.php; + fastcgi_buffers 16 16k; + fastcgi_buffer_size 32k; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + #fixes timeouts + fastcgi_read_timeout 600; + include fastcgi_params; + } + + location ~ /\.ht { + deny all; + } + + location /.well-known/acme-challenge/ { + root /var/www/letsencrypt/; + log_not_found off; + } +}