Skip to content

Commit 8dcadc0

Browse files
committed
Nginx: rework robots config to use ENV vars
1 parent 29899ea commit 8dcadc0

File tree

12 files changed

+61
-7
lines changed

12 files changed

+61
-7
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,16 @@ This is a collection of Docker images, both for development purposes, use during
55
# Development
66

77
Changes to this repository will trigger a build and push to GitHub packages automatically.
8+
9+
# Configuration
10+
11+
## nginx
12+
13+
Images with `nginx` can be configured using the following environment variables.
14+
15+
### Robots
16+
17+
| Environment Key | Applied | Description | Default |
18+
------------------|---------|------------------------
19+
| NGINX_ROBOTS_TAG | Every run | `X-Robots-Tag` value | `none` |
20+
| NGINX_ROBOTS_TXT | Every run | Content of `robots.txt` | `Disallow: /` |

common/config/nginx/site-mods-available.d/no-robots.conf

Lines changed: 0 additions & 2 deletions
This file was deleted.

common/config/nginx/site-mods-enabled.d/no-robots.conf

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env sh
2+
3+
set -euo pipefail
4+
5+
# Configure nginx robots rules based on ENV vars
6+
#
7+
# Inputs:
8+
# - NGINX_ROBOTS_TAG: defaults to 'none'
9+
# - NGINX_ROBOTS_TXT: defaults to 'Disallow: /'
10+
11+
# Set defaults
12+
NGINX_ROBOTS_TAG="${NGINX_ROBOTS_TAG:-none}"
13+
NGINX_ROBOTS_TXT="${NGINX_ROBOTS_TXT:-Disallow: /}"
14+
15+
if [ -d /etc/nginx/site-mods-enabled.d/ ]; then
16+
# robots tag header
17+
echo "Nginx: configuring robots tag header with '${NGINX_ROBOTS_TAG}'…"
18+
cat <<EOF > /etc/nginx/site-mods-enabled.d/generated-robots.conf
19+
# Configure indexing
20+
add_header 'X-Robots-Tag' '${NGINX_ROBOTS_TAG}';
21+
EOF
22+
23+
# robots.txt file
24+
echo "Nginx: configuring robots.txt with '${NGINX_ROBOTS_TXT}'…"
25+
cat <<EOF >> /etc/nginx/site-mods-enabled.d/generated-robots.conf
26+
# Configure crawlers
27+
location = /robots.txt {
28+
add_header 'Content-Type' 'text/plain';
29+
return 200 "User-agent: *\n${NGINX_ROBOTS_TXT}\n";
30+
}
31+
EOF
32+
fi

matomo/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ COPY common/config/supervisor/supervisord.conf /etc/supervisor/
1515
COPY common/config/supervisor/conf.d/nginx.conf /etc/supervisor/conf.d/
1616
COPY matomo/config/supervisor/conf.d/ /etc/supervisor/conf.d/
1717
# - init
18-
COPY matomo/scripts/ /scripts/
18+
COPY common/scripts/ matomo/scripts/ /scripts/
1919

2020
# Configure cron
2121
RUN echo "*/30 * * * * /usr/local/bin/php /var/www/html/console core:archive --verbose --no-interaction" > /etc/crontabs/www-data

matomo/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Serves content on port `8080`.
2020

2121
## Configuration
2222

23+
Check the [general readme](../README.md) for configuring common settings.
24+
2325
This image can be configured using the following environment variables:
2426

2527
| Environment Key | Applied | Description |

nuxt-base/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ COPY common/config/supervisor/supervisord.conf /etc/supervisor/
2020
COPY common/config/supervisor/conf.d/nginx.conf /etc/supervisor/conf.d/
2121
COPY nuxt-base/config/supervisor/conf.d/ /etc/supervisor/conf.d/
2222
# - init
23-
COPY nuxt-base/scripts/ /scripts/
23+
COPY common/scripts/ nuxt-base/scripts/ /scripts/
2424

2525
# Clean Up
2626
WORKDIR /app/www

nuxt-base/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ Docker will default to the `serve` command.
1616
## Info
1717

1818
Serves content on port `8080`.
19+
20+
## Configuration
21+
22+
Check the [general readme](../README.md) for configuring common settings.

php-base/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ COPY php-base/config/php/ /etc/php${PHP_VERSION}/
5555
COPY common/config/supervisor/supervisord.conf /etc/supervisor/
5656
COPY common/config/supervisor/conf.d/nginx.conf /etc/supervisor/conf.d/
5757
# - init
58-
COPY php-base/scripts/ /scripts/
58+
COPY common/scripts/ php-base/scripts/ /scripts/
5959

6060
# Clean Up
6161
WORKDIR /app/www

php-base/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Serves content on port `8080`.
2525

2626
## Configuration
2727

28+
Check the [general readme](../README.md) for configuring common settings.
29+
2830
This image can be configured using the following environment variables:
2931

3032
| Environment Key | Applied | Description | Default |

0 commit comments

Comments
 (0)