Skip to content

Commit d033d8e

Browse files
committed
Fix health monitoring script and update nginx configuration: Ensure correct upstream port handling and set Host header to $http_host
1 parent 8740f42 commit d033d8e

File tree

3 files changed

+115
-3
lines changed

3 files changed

+115
-3
lines changed

health-monitor.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
UPSTREAM_HOST=$(echo $UPSTREAM_SERVER | cut -d: -f1)
77
UPSTREAM_PORT=$(echo $UPSTREAM_SERVER | cut -d: -f2)
88

9+
# Default to port 80 if no port specified
10+
if [ "$UPSTREAM_HOST" = "$UPSTREAM_PORT" ]; then
11+
UPSTREAM_PORT=80
12+
fi
13+
914
echo "Monitoring upstream server: $UPSTREAM_HOST:$UPSTREAM_PORT"
1015

1116
while true; do

nginx.conf.template

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ http {
5656
proxy_connect_timeout 90s;
5757
proxy_read_timeout 90s;
5858
proxy_send_timeout 90s;
59-
proxy_set_header Host $host;
59+
proxy_set_header Host $http_host;
6060
proxy_set_header X-Real-IP $remote_addr;
6161
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
6262
proxy_set_header X-Forwarded-Proto $scheme;
@@ -91,7 +91,7 @@ http {
9191
proxy_connect_timeout 90s;
9292
proxy_read_timeout 90s;
9393
proxy_send_timeout 90s;
94-
proxy_set_header Host $host;
94+
proxy_set_header Host $http_host;
9595
proxy_set_header X-Real-IP $remote_addr;
9696
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
9797
proxy_set_header X-Forwarded-Proto $scheme;
@@ -104,4 +104,4 @@ http {
104104
proxy_cache owlery_cache;
105105
}
106106
}
107-
}
107+
}

nginx.conf.template.backup

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
worker_processes auto;
2+
3+
events {
4+
worker_connections 1024;
5+
}
6+
7+
http {
8+
resolver ${DNS_RESOLVER} valid=30s;
9+
resolver_timeout 5s;
10+
11+
upstream owlery {
12+
server ${UPSTREAM_SERVER};
13+
keepalive 16;
14+
}
15+
16+
log_format cache '$remote_addr - $remote_user [$time_local] "$request" '
17+
'$status $body_bytes_sent "$http_referer" '
18+
'"$http_user_agent" "$http_x_forwarded_for" '
19+
'$upstream_cache_status $request_time $upstream_response_time';
20+
21+
access_log /dev/stdout cache;
22+
error_log /dev/stderr warn;
23+
24+
proxy_cache_path /var/cache/nginx/owlery levels=1:2 keys_zone=owlery_cache:100m max_size=${CACHE_MAX_SIZE} inactive=7776000s use_temp_path=off;
25+
26+
proxy_cache_key "$request_method$request_uri";
27+
proxy_cache_min_uses 1;
28+
proxy_cache_revalidate on;
29+
proxy_cache_methods GET HEAD;
30+
31+
proxy_cache_valid 200 7776000s;
32+
proxy_cache_valid 404 600s;
33+
34+
proxy_cache_use_stale updating;
35+
proxy_cache_background_update on;
36+
proxy_cache_lock on;
37+
38+
server {
39+
listen 80;
40+
41+
location /health {
42+
access_log off;
43+
proxy_pass http://owlery/;
44+
proxy_connect_timeout 3s;
45+
proxy_read_timeout 3s;
46+
proxy_intercept_errors on;
47+
error_page 500 502 503 504 =503 "UPSTREAM_UNAVAILABLE\n";
48+
add_header Content-Type text/plain;
49+
add_header X-Upstream-Status $upstream_status;
50+
}
51+
52+
location / {
53+
proxy_pass http://owlery$request_uri;
54+
proxy_http_version 1.1;
55+
proxy_set_header Connection "";
56+
proxy_connect_timeout 90s;
57+
proxy_read_timeout 90s;
58+
proxy_send_timeout 90s;
59+
proxy_set_header Host $http_host;
60+
proxy_set_header X-Real-IP $remote_addr;
61+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
62+
proxy_set_header X-Forwarded-Proto $scheme;
63+
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
64+
proxy_next_upstream_timeout 30s;
65+
proxy_next_upstream_tries 2;
66+
add_header X-Cache-Status $upstream_cache_status;
67+
add_header X-Cache-Key "$request_method$request_uri";
68+
proxy_ignore_headers Cache-Control Expires Set-Cookie;
69+
proxy_cache owlery_cache;
70+
}
71+
}
72+
73+
server {
74+
listen 8080;
75+
76+
location /health {
77+
access_log off;
78+
proxy_pass http://owlery/;
79+
proxy_connect_timeout 3s;
80+
proxy_read_timeout 3s;
81+
proxy_intercept_errors on;
82+
error_page 500 502 503 504 =503 "UPSTREAM_UNAVAILABLE\n";
83+
add_header Content-Type text/plain;
84+
add_header X-Upstream-Status $upstream_status;
85+
}
86+
87+
location / {
88+
proxy_pass http://owlery$request_uri;
89+
proxy_http_version 1.1;
90+
proxy_set_header Connection "";
91+
proxy_connect_timeout 90s;
92+
proxy_read_timeout 90s;
93+
proxy_send_timeout 90s;
94+
proxy_set_header Host $http_host;
95+
proxy_set_header X-Real-IP $remote_addr;
96+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
97+
proxy_set_header X-Forwarded-Proto $scheme;
98+
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
99+
proxy_next_upstream_timeout 30s;
100+
proxy_next_upstream_tries 2;
101+
add_header X-Cache-Status $upstream_cache_status;
102+
add_header X-Cache-Key "$request_method$request_uri";
103+
proxy_ignore_headers Cache-Control Expires Set-Cookie;
104+
proxy_cache owlery_cache;
105+
}
106+
}
107+
}

0 commit comments

Comments
 (0)