Skip to content

Commit e21e38d

Browse files
authored
Merge pull request #21 from secondlife/signal/skip-health
Disable healthcheck access log
2 parents 051fae7 + 7a79e59 commit e21e38d

File tree

11 files changed

+73
-26
lines changed

11 files changed

+73
-26
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ COPY src /
1111
ENV KEEPALIVE_TIMEOUT=65
1212
ENV PROXY_UWSGI=0
1313
ENV LISTEN_PORT=80
14+
ENV HEALTHCHECK_PATH="/lb-status/"
1415
ENV STATIC_LOCATIONS=
1516
EXPOSE 80
1617
STOPSIGNAL SIGQUIT

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Pair nginx-proxy with your favorite upstream server (wsgi, uwsgi, asgi, et al.)
1616
| `STATIC_LOCATIONS` | Static asset mappings | No | | |
1717
| `PROXY_UWSGI` | Whether to use native uwsgi support | No | 0 | 1 |
1818
| `KEEPALIVE_TIMEOUT` | What value to set HTTP keepalive (This should be higher than your ELB's timeout) | Yes | 65 | |
19+
| `HEALTHCHECK_PATH` | nginx-proxy disables healthcheck path access logs, you can configure the path here | Yes | /lb-status/ | |
1920

2021
### Hosting Static Assets
2122

src/docker-entrypoint.d/00-render-templates.sh

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ set -eo pipefail
44

55
source /docker-entrypoint.d/functions
66

7-
# Render main nginx.conf
8-
cat "/etc/nginx/nginx.conf.template" | gomplate > "/etc/nginx/nginx.conf"
7+
function render_templates {
8+
local src="$1"
9+
local dst="$2"
10+
for f in $src; do
11+
final=$(basename "$f")
12+
final=${final%.template}
13+
final="$dst/$final"
14+
cat "$f" | gomplate > "$final"
15+
log "$0: Rendered $f and moved it to $final"
16+
done
17+
}
918

10-
for f in /etc/nginx/templates/*.template
11-
do
12-
final=$(basename "$f")
13-
final=${final%.template}
14-
final="/etc/nginx/conf.d/$final"
15-
cat "$f" | gomplate > "$final"
16-
log "$0: Rendered $f and moved it to $final"
17-
done
19+
render_templates "/etc/nginx/*.template" "/etc/nginx"
20+
render_templates "/etc/nginx/conf.d/*.template" "/etc/nginx/conf.d"
21+
render_templates "/etc/nginx/includes/*.template" "/etc/nginx/includes"

src/etc/nginx/templates/default.conf.template renamed to src/etc/nginx/conf.d/default.conf.template

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,22 @@ server {
2222
add_header X-XSS-Protection "1; mode=block";
2323
add_header X-Content-Type-Options "nosniff";
2424

25-
{{ if (eq .Env.PROXY_UWSGI "1") }}
2625
location / {
27-
uwsgi_pass app;
28-
uwsgi_param HTTP_X_REQUEST_ID $request_id;
29-
uwsgi_param HTTP_HOST $host;
30-
include uwsgi_params;
31-
uwsgi_read_timeout {{ .Env.KEEPALIVE_TIMEOUT }};
32-
uwsgi_send_timeout {{ .Env.KEEPALIVE_TIMEOUT }};
26+
{{ if (eq .Env.PROXY_UWSGI "1") }}
27+
include /etc/nginx/includes/uwsgi.conf;
28+
{{ else }}
29+
include /etc/nginx/includes/proxy.conf;
30+
{{ end }}
3331
}
34-
{{ else }}
35-
location / {
36-
proxy_set_header X-Request-ID $request_id;
37-
proxy_set_header Host $host;
38-
proxy_redirect off;
39-
proxy_pass http://app;
32+
33+
location {{ .Env.HEALTHCHECK_PATH }} {
34+
access_log off;
35+
{{ if (eq .Env.PROXY_UWSGI "1") }}
36+
include /etc/nginx/includes/uwsgi.conf;
37+
{{ else }}
38+
include /etc/nginx/includes/proxy.conf;
39+
{{ end }}
4040
}
41-
{{ end }}
4241

4342
{{ if .Env.STATIC_LOCATIONS }}
4443
{{ range (.Env.STATIC_LOCATIONS | strings.Split "," )}}

src/etc/nginx/conf.d/status.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# NGINX status/stats used by datadog, et al.
22
server {
33
listen 8091;
4-
server_name localhost;
4+
server_name _;
55

66
access_log off;
77
allow 127.0.0.1;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
proxy_set_header X-Request-ID $request_id;
2+
proxy_set_header Host $host;
3+
proxy_redirect off;
4+
proxy_pass http://app;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
uwsgi_pass app;
2+
uwsgi_param HTTP_X_REQUEST_ID $request_id;
3+
uwsgi_param HTTP_HOST $host;
4+
include uwsgi_params;
5+
uwsgi_read_timeout {{ .Env.KEEPALIVE_TIMEOUT }};
6+
uwsgi_send_timeout {{ .Env.KEEPALIVE_TIMEOUT }};

src/etc/nginx/nginx.conf.template

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ http {
4545
more_clear_headers "Server";
4646
more_clear_headers "server";
4747

48-
include /etc/nginx/conf.d/*.conf;
48+
include /etc/nginx/includes/log-format.conf;
4949

5050
# For docker logs to work, we need to output to stdout/stderr
5151
access_log /dev/stdout json_analytics;
52+
53+
include /etc/nginx/conf.d/*.conf;
5254
}

test/main_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,35 @@ func getHTTPClient() *http.Client {
2727
}
2828
}
2929

30+
func TestHealth(t *testing.T) {
31+
u, err := getTestURL()
32+
if err != nil {
33+
t.Fatal(err)
34+
}
35+
36+
parsed, err := url.Parse(u)
37+
if err != nil {
38+
t.Fatal(err)
39+
}
40+
41+
req, err := http.NewRequest("GET", parsed.JoinPath("/health").String(), nil)
42+
43+
if err != nil {
44+
t.Fatal(err)
45+
}
46+
47+
client := getHTTPClient()
48+
res, err := client.Do(req)
49+
50+
if err != nil {
51+
t.Fatal(err)
52+
}
53+
54+
if res.StatusCode != http.StatusOK {
55+
t.Fatalf("Expected HTTP %d but got %d", http.StatusOK, res.StatusCode)
56+
}
57+
}
58+
3059
func TestStatic(t *testing.T) {
3160
u, err := getTestURL()
3261
if err != nil {

test/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ LISTEN_PORT="8080" \
1111
KEEPALIVE_TIMEOUT="65" \
1212
PROXY_REVERSE_URL="http://localhost:8081" \
1313
SERVER_NAME="localhost" \
14+
HEALTHCHECK_PATH="/health" \
1415
STATIC_LOCATIONS="/static/:/test/static/" \
1516
/docker-entrypoint.sh
1617

0 commit comments

Comments
 (0)