add Dockerfile and docker stuff

time spent: 3.15h
This commit is contained in:
Filipp Frizzy
2021-10-28 17:44:15 +03:00
parent 3a829d4296
commit 6285b6601c
3 changed files with 39 additions and 5 deletions

20
Dockerfile Normal file
View File

@@ -0,0 +1,20 @@
ARG NGINX_VERSION=latest
FROM nginx:${NGINX_VERSION} AS nginx
ARG USER=nginx
ARG UID=101
ARG GID=101
COPY nginx.conf /etc/nginx/nginx.conf
COPY conf.d/ /etc/nginx/conf.d/
COPY snippets/ /etc/nginx/snippets/
COPY templates/ /etc/nginx/templates/
COPY --chown=$USER:$USER html/ /usr/share/nginx/html/
RUN if [ "$(dpkg --print-architecture)" = "amd64" ]; then \
curl -sL https://github.com/a8m/envsubst/releases/download/v1.2.0/envsubst-Linux-x86_64 -o /usr/bin/envsubst && \
chmod +x /usr/bin/envsubst; fi; \
if [ "$(cat /etc/apk/arch)" = "x86_64" ]; then \
curl -sL https://github.com/a8m/envsubst/releases/download/v1.2.0/envsubst-Linux-x86_64 -o /usr/local/bin/envsubst && \
chmod +x /usr/local/bin/envsubst; fi;

View File

@@ -30,11 +30,13 @@ Collection of Nginx configs for most popular CMS/CMF/Frameworks based on PHP.
Docker image, but I haven't checked it properly yet, their configs require addition nginx modules and setup
and it can't be just copied to the usual nginx setup. However, you can use it with docker.
Also I don't agree with nginx microcache for every site, see known traps.
- [hub.docker.com/_/nginx](https://hub.docker.com/_/nginx/)
Official nginx docker image and docs.
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 :)
Time track:
- [Filipp Frizzy](https://github.com/Friz-zy/) 42.41h
- [Filipp Frizzy](https://github.com/Friz-zy/) 45.56h
### Support
@@ -92,6 +94,9 @@ Template of common site configuration
* `static_location.conf`
Include with location for static files
# Dockerfile
`Dockerfile` example with build args, configs copying and custom envsubst template engine
#### Docker-compose
`docker-compose.yml` example for nginx
@@ -265,6 +270,13 @@ Then valid user after visit to the their site will be automatically blocked on y
You can fight with this practice using `http_referer`, see `snippets/referer.conf.j2` template ;)
Warning: I have not tested this code yet
#### Default templating engine in official docker image can't proceed variables with default values like `${var:-$DEFAULT}`
By default nginx in docker use [GNU envsubst](https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.html)
that [can't proceed variables with default values](https://stackoverflow.com/questions/50230361/envsubst-default-values-for-unset-variables).
You can use instead [a8m envsubst](https://github.com/a8m/envsubst) or [stephenc envsub](https://github.com/stephenc/envsub),
first one already has a prebuilded binary for x86_64 arch, check the `Dockerfile` in this repo ;)
#### Includes like `<dir>/*.conf` are processed in the alphabetic order
This is important for nginx in docker as all configs are located in one dir

View File

@@ -8,6 +8,7 @@ services:
- nginx.conf:/etc/nginx/nginx.conf
- conf.d:/etc/nginx/conf.d
- snippets:/etc/nginx/snippets
- templates:/etc/nginx/templates
#- /etc/nginx:/etc/nginx
#- /etc/letsencrypt:/etc/letsencrypt
- /etc/ssl:/etc/ssl
@@ -23,7 +24,8 @@ services:
soft: 100000
hard: 100000
restart: unless-stopped
logging:
driver: journald
options:
tag: "docker/nginx/{{.Name}}"
logging:
driver: json-file
options:
max-size: "100m"
max-file: "5"