Nginx returns "upstream timed out" when IPv6 is enabled on the host

I have both nginx v1.15.7 and gitea 1.6.0 running on a Windows 2016 server VM.
It seems as gitea always resolves “localhost” to IPv4 address even though, by default, Windows Server prioritizes IPv6 over IPv4. Nginx resolves “localhost” based on the current Windows prioritization thus preventing the proxy from working.

Gitea config:

PROTOCOL         = https
DOMAIN           =
HTTP_ADDR        =
HTTP_PORT        = 3000
CERT_FILE        = C:/Inet/cert/contoso.pem
KEY_FILE         = C:/Inet/cert/contoso.pem
ROOT_URL         =

Nginx config:

server {
    listen         ssl;
    server_name             ~(?i)^git\.contoso\.com$;

    location /              {

Contoso DNS server config:      ::1            OK      OK      localhost      Nginx proxy returns "upstream timed out"

Is this a gitea bug or is there any way to force gitea to resolve “localhost” according to current host prioritization?

Why do you not change your vhost config to instead of the localhost?

We have a valid CA signed certificate for our domain. With https enabled, the browser won’t let you access