Add a Nginx template using a dynamic hostname from .env
This commit is contained in:
4
.env
4
.env
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
# See https://docs.docker.com/compose/environment-variables/#the-env-file
|
# See https://docs.docker.com/compose/environment-variables/#the-env-file
|
||||||
|
|
||||||
|
# Nginx
|
||||||
|
NGINX_HOST=localhost
|
||||||
|
|
||||||
|
# MySQL
|
||||||
MYSQL_HOST=mysql
|
MYSQL_HOST=mysql
|
||||||
MYSQL_DATABASE=test
|
MYSQL_DATABASE=test
|
||||||
MYSQL_ROOT_USER=root
|
MYSQL_ROOT_USER=root
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -53,7 +53,7 @@ docker-stop:
|
|||||||
@make clean
|
@make clean
|
||||||
|
|
||||||
gen-certs:
|
gen-certs:
|
||||||
@docker run --rm -v $(shell pwd)/etc/ssl:/certificates -e "SERVER=localhost" jacoelho/generate-certificate
|
@docker run --rm -v $(shell pwd)/etc/ssl:/certificates -e "SERVER=$(NGINX_HOST)" jacoelho/generate-certificate
|
||||||
|
|
||||||
logs:
|
logs:
|
||||||
@docker-compose logs -f
|
@docker-compose logs -f
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
version: '3'
|
version: '3'
|
||||||
services:
|
services:
|
||||||
web:
|
web:
|
||||||
image: nginx:latest
|
image: nginx
|
||||||
ports:
|
|
||||||
- "8000:80"
|
|
||||||
- "3000:443"
|
|
||||||
restart: always
|
|
||||||
volumes:
|
volumes:
|
||||||
- "./etc/nginx/default.conf:/etc/nginx/conf.d/default.conf"
|
- "./etc/nginx/default.conf:/etc/nginx/conf.d/default.conf"
|
||||||
- "./etc/ssl:/etc/ssl"
|
- "./etc/ssl:/etc/ssl"
|
||||||
- "./web:/var/www/html"
|
- "./web:/var/www/html"
|
||||||
|
- "./etc/nginx/default.template:/etc/nginx/conf.d/default.template"
|
||||||
|
ports:
|
||||||
|
- "8000:80"
|
||||||
|
- "3000:443"
|
||||||
|
environment:
|
||||||
|
- NGINX_HOST=${NGINX_HOST}
|
||||||
|
command: /bin/bash -c "envsubst '$$NGINX_HOST' < /etc/nginx/conf.d/default.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
|
||||||
|
restart: always
|
||||||
depends_on:
|
depends_on:
|
||||||
- php
|
- php
|
||||||
- mysqldb
|
- mysqldb
|
||||||
|
|||||||
@@ -21,28 +21,28 @@ server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# server {
|
server {
|
||||||
# server_name localhost;
|
server_name localhost;
|
||||||
|
|
||||||
# listen 443 ssl;
|
listen 443 ssl;
|
||||||
# fastcgi_param HTTPS on;
|
fastcgi_param HTTPS on;
|
||||||
|
|
||||||
# ssl_certificate /etc/ssl/server.pem;
|
ssl_certificate /etc/ssl/server.pem;
|
||||||
# ssl_certificate_key /etc/ssl/server.key;
|
ssl_certificate_key /etc/ssl/server.key;
|
||||||
# ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
|
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
|
||||||
|
|
||||||
# index index.php index.html;
|
index index.php index.html;
|
||||||
# error_log /var/log/nginx/error.log;
|
error_log /var/log/nginx/error.log;
|
||||||
# access_log /var/log/nginx/access.log;
|
access_log /var/log/nginx/access.log;
|
||||||
# root /var/www/html/public;
|
root /var/www/html/public;
|
||||||
|
|
||||||
# location ~ \.php$ {
|
location ~ \.php$ {
|
||||||
# try_files $uri =404;
|
try_files $uri =404;
|
||||||
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||||
# fastcgi_pass php:9000;
|
fastcgi_pass php:9000;
|
||||||
# fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
# include fastcgi_params;
|
include fastcgi_params;
|
||||||
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||||
# fastcgi_param PATH_INFO $fastcgi_path_info;
|
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||||
# }
|
}
|
||||||
# }
|
}
|
||||||
48
etc/nginx/default.template
Normal file
48
etc/nginx/default.template
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
# Nginx configuration
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 80 default_server;
|
||||||
|
listen [::]:80 default_server;
|
||||||
|
server_name ${NGINX_HOST};
|
||||||
|
|
||||||
|
index index.php index.html;
|
||||||
|
error_log /var/log/nginx/error.log;
|
||||||
|
access_log /var/log/nginx/access.log;
|
||||||
|
root /var/www/html/public;
|
||||||
|
|
||||||
|
location ~ \.php$ {
|
||||||
|
try_files $uri =404;
|
||||||
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||||
|
fastcgi_pass php:9000;
|
||||||
|
fastcgi_index index.php;
|
||||||
|
include fastcgi_params;
|
||||||
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||||
|
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
server_name ${NGINX_HOST};
|
||||||
|
|
||||||
|
listen 443 ssl;
|
||||||
|
fastcgi_param HTTPS on;
|
||||||
|
|
||||||
|
ssl_certificate /etc/ssl/server.pem;
|
||||||
|
ssl_certificate_key /etc/ssl/server.key;
|
||||||
|
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
|
||||||
|
|
||||||
|
index index.php index.html;
|
||||||
|
error_log /var/log/nginx/error.log;
|
||||||
|
access_log /var/log/nginx/access.log;
|
||||||
|
root /var/www/html/public;
|
||||||
|
|
||||||
|
location ~ \.php$ {
|
||||||
|
try_files $uri =404;
|
||||||
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||||
|
fastcgi_pass php:9000;
|
||||||
|
fastcgi_index index.php;
|
||||||
|
include fastcgi_params;
|
||||||
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||||
|
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user