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
|
||||
|
||||
# Nginx
|
||||
NGINX_HOST=localhost
|
||||
|
||||
# MySQL
|
||||
MYSQL_HOST=mysql
|
||||
MYSQL_DATABASE=test
|
||||
MYSQL_ROOT_USER=root
|
||||
|
||||
2
Makefile
2
Makefile
@@ -53,7 +53,7 @@ docker-stop:
|
||||
@make clean
|
||||
|
||||
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:
|
||||
@docker-compose logs -f
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
version: '3'
|
||||
services:
|
||||
web:
|
||||
image: nginx:latest
|
||||
ports:
|
||||
- "8000:80"
|
||||
- "3000:443"
|
||||
restart: always
|
||||
image: nginx
|
||||
volumes:
|
||||
- "./etc/nginx/default.conf:/etc/nginx/conf.d/default.conf"
|
||||
- "./etc/ssl:/etc/ssl"
|
||||
- "./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:
|
||||
- php
|
||||
- mysqldb
|
||||
|
||||
@@ -21,28 +21,28 @@ server {
|
||||
}
|
||||
}
|
||||
|
||||
# server {
|
||||
# server_name localhost;
|
||||
server {
|
||||
server_name localhost;
|
||||
|
||||
# listen 443 ssl;
|
||||
# fastcgi_param HTTPS on;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
# }
|
||||
# }
|
||||
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;
|
||||
}
|
||||
}
|
||||
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