Skip to content

Commit 6285b66

Browse files
committed
add Dockerfile and docker stuff
time spent: 3.15h
1 parent 3a829d4 commit 6285b66

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ARG NGINX_VERSION=latest
2+
3+
FROM nginx:${NGINX_VERSION} AS nginx
4+
ARG USER=nginx
5+
ARG UID=101
6+
ARG GID=101
7+
8+
COPY nginx.conf /etc/nginx/nginx.conf
9+
COPY conf.d/ /etc/nginx/conf.d/
10+
COPY snippets/ /etc/nginx/snippets/
11+
COPY templates/ /etc/nginx/templates/
12+
13+
COPY --chown=$USER:$USER html/ /usr/share/nginx/html/
14+
15+
RUN if [ "$(dpkg --print-architecture)" = "amd64" ]; then \
16+
curl -sL https://github.com/a8m/envsubst/releases/download/v1.2.0/envsubst-Linux-x86_64 -o /usr/bin/envsubst && \
17+
chmod +x /usr/bin/envsubst; fi; \
18+
if [ "$(cat /etc/apk/arch)" = "x86_64" ]; then \
19+
curl -sL https://github.com/a8m/envsubst/releases/download/v1.2.0/envsubst-Linux-x86_64 -o /usr/local/bin/envsubst && \
20+
chmod +x /usr/local/bin/envsubst; fi;

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ Collection of Nginx configs for most popular CMS/CMF/Frameworks based on PHP.
3030
Docker image, but I haven't checked it properly yet, their configs require addition nginx modules and setup
3131
and it can't be just copied to the usual nginx setup. However, you can use it with docker.
3232
Also I don't agree with nginx microcache for every site, see known traps.
33+
- [hub.docker.com/_/nginx](https://hub.docker.com/_/nginx/)
34+
Official nginx docker image and docs.
3335

3436
So here I'm trying to put together all (my) good patterns and knowledge, and organize it as simply as possible in comparison with complex examples above. So anyone will be able to copy this configs and get a good nginx setup out of the box :)
3537

3638
Time track:
37-
- [Filipp Frizzy](https://github.com/Friz-zy/) 42.41h
39+
- [Filipp Frizzy](https://github.com/Friz-zy/) 45.56h
3840

3941
### Support
4042

@@ -92,6 +94,9 @@ Template of common site configuration
9294
* `static_location.conf`
9395
Include with location for static files
9496

97+
# Dockerfile
98+
`Dockerfile` example with build args, configs copying and custom envsubst template engine
99+
95100
#### Docker-compose
96101
`docker-compose.yml` example for nginx
97102

@@ -265,6 +270,13 @@ Then valid user after visit to the their site will be automatically blocked on y
265270
You can fight with this practice using `http_referer`, see `snippets/referer.conf.j2` template ;)
266271
Warning: I have not tested this code yet
267272

273+
#### Default templating engine in official docker image can't proceed variables with default values like `${var:-$DEFAULT}`
274+
275+
By default nginx in docker use [GNU envsubst](https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.html)
276+
that [can't proceed variables with default values](https://stackoverflow.com/questions/50230361/envsubst-default-values-for-unset-variables).
277+
You can use instead [a8m envsubst](https://github.com/a8m/envsubst) or [stephenc envsub](https://github.com/stephenc/envsub),
278+
first one already has a prebuilded binary for x86_64 arch, check the `Dockerfile` in this repo ;)
279+
268280
#### Includes like `<dir>/*.conf` are processed in the alphabetic order
269281

270282
This is important for nginx in docker as all configs are located in one dir

docker-compose.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ services:
88
- nginx.conf:/etc/nginx/nginx.conf
99
- conf.d:/etc/nginx/conf.d
1010
- snippets:/etc/nginx/snippets
11+
- templates:/etc/nginx/templates
1112
#- /etc/nginx:/etc/nginx
1213
#- /etc/letsencrypt:/etc/letsencrypt
1314
- /etc/ssl:/etc/ssl
@@ -23,7 +24,8 @@ services:
2324
soft: 100000
2425
hard: 100000
2526
restart: unless-stopped
26-
logging:
27-
driver: journald
28-
options:
29-
tag: "docker/nginx/{{.Name}}"
27+
logging:
28+
driver: json-file
29+
options:
30+
max-size: "100m"
31+
max-file: "5"

0 commit comments

Comments
 (0)