According to this post and also here using a variable for the upstream server like this:
location /git/ {
resolver 127.0.0.11 ipv6=off valid=30s; ## internal docker dns set
$upstream http://gitea:3000/;
proxy_pass $upstream;
}
allows nginx to start even when the upstream service isn't available.
However having tried this all the requests to /git/ return the document root.
Here's a gotcha.
Here's a solution.
location /git/ {
resolver 127.0.0.11 ipv6=off valid=30s; ## internal docker dns set
$upstream http://gitea:3000/$uri$is_args$args;
proxy_pass $upstream;
}
However this means that root level requests like https://sigyl.com/git/giles 404
Configure logging of proxy passes in the log_format directive:
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'
'"$proxy_host" "$upstream_addr"';
looking at the gitea logs - these requests are 404ing because the /git/ at the start is included:
[Macaron] 2020-05-03 08:27:59: Completed GET //git/ 404 Not Found in 1.997719ms
[Macaron] 2020-05-03 08:27:59: Started GET //git/img/404.png for 10.0.11.4
[Macaron] 2020-05-03 08:27:59: Completed GET //git/img/404.png 404 Not Found in 2.133087ms
[Macaron] 2020-05-03 08:28:02: Started GET //git/serviceworker.js for 10.0.11.4
[Macaron] 2020-05-03 08:28:02: Completed GET //git/serviceworker.js 404 Not Found in 1.998517m
This post talks about how to remove the location from the uri.
I ended up using a regex like this:
location ~ /git/(.*) {
resolver 127.0.0.11 ipv6=off valid=30s; ## internal docker dns set
$upstream http://gitea:3000/$1$is_args$args;
proxy_pass $upstream;
}
Now if I stop gitea service and restart the proxy:
docker service scale gitea_gitea=0
docker kill ef791407a0ac
it stays up.