Skip to content

Commit 4cf0d1c

Browse files
committed
add ssl conf
1 parent b40b70e commit 4cf0d1c

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

base/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ RUN ln -sf /dev/stderr /var/log/nginx/access.log \
2323

2424
RUN rm -f /etc/nginx/sites-enabled/*
2525

26-
COPY nginx.conf.tpl /tmp/nginx.conf.tpl
27-
COPY php-fpm.conf.tpl /tmp/php-fpm.conf.tpl
26+
COPY nginx.conf.tpl /nginx.conf.tpl
27+
COPY nginx_ssl.conf.tpl /nginx_ssl.conf.tpl
28+
COPY php-fpm.conf.tpl /php-fpm.conf.tpl
2829
COPY defaults.ini /etc/php/7.2/cli/conf.d/defaults.ini
2930
COPY defaults.ini /etc/php/7.2/fpm/conf.d/defaults.ini
3031

base/entrypoint.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@ export NGINX_PHP_FALLBACK=${NGINX_PHP_FALLBACK:-'/index.php'}
55
export NGINX_PHP_LOCATION=${NGINX_PHP_LOCATION:-'^/index\.php(/|$$)'}
66
export NGINX_USER=${NGINX_USER:-'www-data'}
77
export NGINX_CONF=${NGINX_CONF:-'/etc/nginx/nginx.conf'}
8+
export NGINX_SSL_PUBLIC_CERTIFICATE=${NGINX_SSL_PUBLIC_CERTIFICATE:-''}
9+
export NGINX_SSL_PRIVATE_CERTIFICATE=${NGINX_SSL_PRIVATE_CERTIFICATE:-''}
810

911
export PHP_SOCK_FILE=${PHP_SOCK_FILE:-'/run/php.sock'}
1012
export PHP_USER=${PHP_USER:-'www-data'}
1113
export PHP_GROUP=${PHP_GROUP:-'www-data'}
1214
export PHP_MODE=${PHP_MODE:-'0660'}
1315
export PHP_FPM_CONF=${PHP_FPM_CONF:-'/etc/php/7.2/fpm/php-fpm.conf'}
1416

15-
envsubst '${NGINX_WEB_ROOT} ${NGINX_PHP_FALLBACK} ${NGINX_PHP_LOCATION} ${NGINX_USER} ${NGINX_CONF} ${PHP_SOCK_FILE} ${PHP_USER} ${PHP_GROUP} ${PHP_MODE} ${PHP_FPM_CONF}' < /tmp/nginx.conf.tpl > $NGINX_CONF
16-
envsubst '${NGINX_WEB_ROOT} ${NGINX_PHP_FALLBACK} ${NGINX_PHP_LOCATION} ${NGINX_USER} ${NGINX_CONF} ${PHP_SOCK_FILE} ${PHP_USER} ${PHP_GROUP} ${PHP_MODE} ${PHP_FPM_CONF}' < /tmp/php-fpm.conf.tpl > $PHP_FPM_CONF
17+
envsubst '${NGINX_WEB_ROOT} ${NGINX_PHP_FALLBACK} ${NGINX_PHP_LOCATION} ${NGINX_USER} ${NGINX_CONF} ${PHP_SOCK_FILE} ${PHP_USER} ${PHP_GROUP} ${PHP_MODE} ${PHP_FPM_CONF}' < /nginx.conf.tpl > $NGINX_CONF
18+
envsubst '${NGINX_WEB_ROOT} ${NGINX_PHP_FALLBACK} ${NGINX_PHP_LOCATION} ${NGINX_USER} ${NGINX_CONF} ${PHP_SOCK_FILE} ${PHP_USER} ${PHP_GROUP} ${PHP_MODE} ${PHP_FPM_CONF}' < /php-fpm.conf.tpl > $PHP_FPM_CONF
19+
20+
if [ ! -z "$NGINX_SSL_PUBLIC_CERTIFICATE" ]
21+
then
22+
envsubst '${NGINX_SSL_PUBLIC_CERTIFICATE} ${NGINX_SSL_PRIVATE_CERTIFICATE} ${NGINX_WEB_ROOT} ${NGINX_PHP_FALLBACK} ${NGINX_PHP_LOCATION} ${NGINX_USER} ${NGINX_CONF} ${PHP_SOCK_FILE} ${PHP_USER} ${PHP_GROUP} ${PHP_MODE} ${PHP_FPM_CONF}' < /nginx_ssl.conf.tpl > /etc/nginx/conf.d/nginx_ssl.conf
23+
fi
1724

1825
TRAPPED_SIGNAL=false
1926

base/nginx_ssl.conf.tpl

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
server {
3+
listen 443 ssl http2 default_server;
4+
listen [::]:443 ssl http2 default_server;
5+
root $NGINX_WEB_ROOT;
6+
7+
location / {
8+
try_files $uri $NGINX_PHP_FALLBACK$is_args$args;
9+
}
10+
location ~ $NGINX_PHP_LOCATION {
11+
fastcgi_pass unix:$PHP_SOCK_FILE;
12+
fastcgi_split_path_info ^(.+\.php)(/.*)$;
13+
include fastcgi_params;
14+
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
15+
fastcgi_param DOCUMENT_ROOT $realpath_root;
16+
17+
internal;
18+
}
19+
20+
# return 404 for all other php files not matching the front controller
21+
# this prevents access to other php files you don't want to be accessible.
22+
location ~ \.php$ {
23+
return 404;
24+
}
25+
26+
ssl_certificate $NGINX_SSL_PUBLIC_CERTIFICATE;
27+
ssl_certificate_key $NGINX_SSL_PRIVATE_CERTIFICATE;
28+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
29+
ssl_prefer_server_ciphers on;
30+
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
31+
ssl_ecdh_curve secp384r1;
32+
ssl_session_cache shared:SSL:10m;
33+
ssl_session_tickets off;
34+
ssl_stapling on;
35+
ssl_stapling_verify on;
36+
resolver 8.8.8.8 8.8.4.4 valid=300s;
37+
resolver_timeout 5s;
38+
# Disable preloading HSTS for now. You can use the commented out header line that includes
39+
# the "preload" directive if you understand the implications.
40+
#add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
41+
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";
42+
add_header X-Frame-Options DENY;
43+
add_header X-Content-Type-Options nosniff;
44+
}

0 commit comments

Comments
 (0)