Skip to content

Commit f13b5b2

Browse files
committed
fix: rename env variables, fix nginx configuring
1 parent 35f916a commit f13b5b2

4 files changed

Lines changed: 19 additions & 14 deletions

File tree

Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ ARG PHP_VERSION=7.4.33
44
FROM php:$PHP_VERSION-fpm-$DEBIAN_VERSION
55

66
# Add environment variables for domain and port
7-
ENV SERVER_NAME="localhost"
8-
ENV SSL_ENABLED="false"
9-
ENV CERTBOT_ENABLED="true"
7+
ENV DOMAIN_NAME="localhost"
8+
ENV HTTPS_ENABLED="false"
9+
ENV LETSENCRYPT_ENABLED="true"
1010

1111
ENV WP_DB_HOST="hub.docker.internal"
1212
ENV WP_DB_USER="wordpress"
@@ -139,6 +139,8 @@ COPY ./nginx/options-ssl-nginx.conf /etc/nginx/ssl/options-ssl-nginx.conf
139139
RUN openssl dhparam -out /etc/nginx/ssl/ssl-dhparams.pem 2048
140140
# Create a directory for SSL certificates when certbot is disabled
141141
RUN mkdir "/var/ssl";
142+
# Remove the default Nginx configuration file, later we will generate new one
143+
RUN rm -f /etc/nginx/conf.d/default.conf
142144

143145
# Expose the default Nginx ports
144146
EXPOSE 80

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ services:
7575
- ./mysql/data:/var/lib/mysql
7676
```
7777
78-
The default port is 80. If you want to support HTTPS, you can set the environment variable SERVER_NAME, SSL_ENABLED to true, and publish the 443 port.
78+
The default port is 80. If you want to support HTTPS, you can set the environment variable DOMAIN_NAME, HTTPS_ENABLED to true, and publish the 443 port.
7979
8080
Below is the example, to set HTTPS for domain name "example.com", so you can visit https://example.com.
8181
@@ -88,9 +88,9 @@ services:
8888
- 80:80
8989
- 443:443
9090
environment:
91-
- SERVER_NAME=example.com
92-
- SSL_ENABLED=true
93-
- CERTBOT_ENABLED=true
91+
- DOMAIN_NAME=example.com
92+
- HTTPS_ENABLED=true
93+
- LETSENCRYPT_ENABLED=true
9494
- WP_DB_HOST=db
9595
- WP_DB_USER=wordpress
9696
- WP_DB_PASSWORD=password
@@ -112,9 +112,9 @@ services:
112112
- ./mysql/data:/var/lib/mysql
113113
```
114114
115-
Note that we use letsencrypt's certbot to generate SSL certificates for you, you need to prove the domain is controlled by you, in most case your domain name should already resolved to the host you run this container, otherwise the certbot will fail, and the container will not be able to serve.
115+
Note that we use letsencrypt to generate SSL certificates for you, you need to prove the domain is controlled by you, in most case your domain name should already resolved to the host you run this container, otherwise the certbot will fail to generate certificate, the website will only serve on 80 port.
116116
117-
However, if you want to use your own certificate or if your environment does not support certbot to automatically generate certificate, you can set CERTBOT_ENABLED to false, and mount a volumn to /var/ssl, then put your own fullchain.pem and privkey.pem to this folder.
117+
However, if you want to use your own certificate or if your environment does not support letsencrypt to automatically generate certificate, you can set LETSENCRYPT_ENABLED to false, and mount a volumn to /var/ssl, then put your own fullchain.pem and privkey.pem to this folder. The website will not serve before the two files are properly placed.
118118
119119
## Develop
120120
Feel free to visit the repository site on Github: [https://github.com/augwit/wordpress/](https://github.com/augwit/wordpress/)

entrypoint.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
#!/bin/bash
22

3-
if [ -z "$(ls -A /etc/nginx/conf.d)" ]; then
3+
if [ ! -f /etc/nginx/conf.d/default.conf ]; then
44
cp /usr/src/nginx-defaults/default.conf /etc/nginx/conf.d/;
55
cp /usr/src/nginx-defaults/wordpress.conf.include /etc/nginx/conf.d/wordpress.conf.include
66

77
# Update entrypoint to configure Nginx and configure SSL certificates
8-
sed -i "s/server_name localhost;/server_name $SERVER_NAME;/" /etc/nginx/conf.d/default.conf
8+
sed -i "s/server_name localhost;/server_name $DOMAIN_NAME;/" /etc/nginx/conf.d/default.conf
99

1010
# If SSL is enabled and Certbot is not enabled, copy the default SSL configuration
11-
if [ "$SSL_ENABLED" = "true" ] && [ "$CERTBOT_ENABLED" = "false" ]; then
11+
if [ "$HTTPS_ENABLED" = "true" ] && [ "$LETSENCRYPT_ENABLED" = "false" ]; then
1212
cp /usr/src/nginx-defaults/default_ssl.conf /etc/nginx/conf.d/;
1313
fi
1414

1515
# If SSL is enabled and Certbot is enabled, run Certbot to obtain SSL certificates
16-
if [ "$SSL_ENABLED" = "true" ] && [ "$CERTBOT_ENABLED" = "true" ]; then
17-
certbot --nginx -d $SERVER_NAME --non-interactive --agree-tos --register-unsafely-without-email -m admin@$SERVER_NAME
16+
if [ "$HTTPS_ENABLED" = "true" ] && [ "$LETSENCRYPT_ENABLED" = "true" ]; then
17+
certbot --nginx -d $DOMAIN_NAME --non-interactive --agree-tos --register-unsafely-without-email -m admin@$DOMAIN_NAME
1818
# cerrtbot started nginx but we need to stop it for now. Later we will start it in the foreground.
1919
service nginx stop
2020
fi

tests/docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ services:
55
ports:
66
- 80:80
77
environment:
8+
- DOMAIN_NAME=localhost
9+
- HTTPS_ENABLED=true
10+
- LETSENCRYPT_ENABLED=true
811
- WP_DB_HOST=db
912
- WP_DB_USER=wordpress
1013
- WP_DB_PASSWORD=password

0 commit comments

Comments
 (0)