Skip to content

Commit 0f7b7d6

Browse files
author
Bryan Latten
committed
Merge pull request #2 from bryanlatten/feature-server-options
Dockerfile/run: allowing changes via env vars
2 parents e25eb9a + ac6c8e9 commit 0f7b7d6

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ MAINTAINER Bryan Latten <[email protected]>
33

44
# Install pre-reqs, security updates
55
RUN apt-get update && \
6+
apt-get upgrade -yq && \
67
apt-get -yq install \
78
openssl=1.0.1f-1ubuntu2.15 \
89
ca-certificates=20141019ubuntu0.14.04.1 \

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
# docker-nginx
22
Provides base OS, patches and stable nginx for quick and easy spinup
3+
4+
5+
Variable | Example | Description
6+
--- | --- | ---
7+
`SERVER_MAX_BODY_SIZE` | `SERVER_MAX_BODY_SIZE=4M` | Allows the downstream application to specify a non-default `client_max_body_size` configuration for the `server`-level directive in `/etc/nginx/sites-available/default`
8+
`SERVER_INDEX` | `SERVER_INDEX index.html index.html index.php | Changes the default pages to hit for folder and web roots

container/root/etc/nginx/sites-available/default

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
# NOTE: the syntax in most directives is sadly duplicated in run.sh,
2+
# in order to replace at runtime with `sed`, therefore, check for changes in both places
13
server {
24
listen 80;
35

46
server_tokens off; # Doesn't broadcast version level of server software
5-
server_name web; # TODO: replace with environment variable
67

8+
# Replace with env variable SERVER_INDEX
79
index index.html index.htm;
810

11+
# Replace with env variable SERVER_MAX_BODY_SIZE
12+
client_max_body_size 1m;
13+
914
location / {
10-
# Check for file or folder first, otherwise rewrite to front controller
1115
try_files $uri $uri/ =404;
1216
}
1317

container/root/run.sh

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
#!/bin/bash
2+
CONFIG_SITE=/etc/nginx/sites-available/default
3+
CONFIG_SERVER=/etc/nginx/nginx.conf
24

3-
echo 'Setting sensible nginx defaults'
5+
echo '[nginx] setting sensible defaults'
46

57
# Configure nginx to use as many workers as there are cores for the running container
6-
sed -i "s/worker_processes [0-9]\+/worker_processes $(nproc)/" /etc/nginx/nginx.conf
7-
sed -i "s/worker_connections [0-9]\+/worker_connections 1024/" /etc/nginx/nginx.conf
8+
sed -i "s/worker_processes [0-9]\+/worker_processes $(nproc)/" $CONFIG_SERVER
9+
sed -i "s/worker_connections [0-9]\+/worker_connections 1024/" $CONFIG_SERVER
810

9-
# Ensure nginx is configured to write logs to STDOUT
10-
sed -i "s/access_log [a-z\/\.\;]\+/access_log \/dev\/stdout;/" /etc/nginx/nginx.conf
11-
sed -i "s/error_log [a-z\/\.\ \;]\+/error_log \/dev\/stdout info;/" /etc/nginx/nginx.conf
11+
echo '[nginx] piping logs to STDOUT'
1212

13-
echo "Starting Nginx (foreground)"
13+
sed -i "s/access_log [a-z\/\.\;]\+/access_log \/dev\/stdout;/" $CONFIG_SERVER
14+
sed -i "s/error_log [a-z\/\.\ \;]\+/error_log \/dev\/stdout info;/" $CONFIG_SERVER
15+
16+
if [[ $SERVER_MAX_BODY_SIZE ]]
17+
then
18+
echo "[nginx] server client max body is ${SERVER_MAX_BODY_SIZE}"
19+
sed -i "s/client_max_body_size 1m/client_max_body_size ${SERVER_MAX_BODY_SIZE}/" $CONFIG_SITE
20+
fi
21+
22+
if [[ $SERVER_INDEX ]]
23+
then
24+
echo "[nginx] server index is ${SERVER_INDEX}"
25+
sed -i "s/index index.html index.htm/index ${SERVER_INDEX}/" $CONFIG_SITE
26+
fi
27+
28+
echo "[nginx] starting (foreground)"
1429
exec /usr/sbin/nginx -g "daemon off;"

0 commit comments

Comments
 (0)