# Configure DNS. Point to Consul resolver consul:53 valid=2s; resolver_timeout 2s; # The upstreams will be populated via DNS upstream unitcnt { zone unitcnt 64k; server service.consul service=unitcnt resolve; } upstream unitcpu { zone unitcpu 64k; server service.consul service=unitcpu resolve; } upstream unitmem { zone unitmem 64k; server service.consul service=unitmem resolve; } # All successful health checks will have a string starting with {“HealthCheck":"OK" match server_ok { status 200; body ~ '{"HealthCheck":"OK"'; } server { # Allows calling upstream health checks directly listen 80; location /healthcheck { proxy_pass http://$arg_server/hcheck.php; } location /healthcheckpy { proxy_pass http://$arg_server/testcnt.py?healthcheck; } } server { listen 8001; status_zone unitcnt; root /usr/share/nginx/html; proxy_http_version 1.1; proxy_set_header Connection ""; location ~ \.py$ { proxy_set_header Host $http_host; proxy_pass http://unitcnt; proxy_intercept_errors on; proxy_next_upstream http_503; # If all the servers are busy return apibusy.html error_page 502 503 =503 /apibusy.html; health_check uri=/testcnt.py?healthcheck match=server_ok interval=1s; } } server { listen 8002; status_zone unitcpu; root /usr/share/nginx/html; proxy_http_version 1.1; proxy_set_header Connection ""; location ~ \.php$ { proxy_set_header Host $http_host; proxy_pass http://unitcpu; error_page 502 =503 /apibusy.html; health_check uri=/hcheck.php match=server_ok interval=5s; } } server { listen 8003; status_zone unitmem; root /usr/share/nginx/html; proxy_http_version 1.1; proxy_set_header Connection ""; location ~ \.php$ { proxy_set_header Host $http_host; proxy_pass http://unitmem; error_page 502 =503 /apibusy.html; health_check uri=/hcheck.php match=server_ok interval=3s; } } # Configure the status API and dashboard server { listen 8082; root /usr/share/nginx/html; location = /dashboard.html { } location = / { return 302 /dashboard.html; } location /api { access_log off; api; } }