NGINX Time Out Issue

Ngnix Time out issue

We have nginx config for routing to another domain for certain endpoints which through AWS Route 53 calls to load balancer.

The routing works fine but after few days we face time out issue until we restart nginx container, though we have added resolver still we see time out happen after certain days, Adding below config for reference :-

**
server {
listen 443 ssl;
server_name appl1.xyz.com;
resolver 169.254.169.253 valid=30s;

# Initial configuration that experienced timeouts
location ~ ^/(url1|url2)$ {

  

    proxy_pass https://appl2-prod.bytemark.co;
    proxy_set_header Host appl2-prod.bytemark.co;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}

location / {
           
            proxy_pass https://appl1-prod:9120;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
    }

}

Note : proxy_pass https://appl2-prod.bytemark.co; this directly added as static content instead of using variable, IS it the reason resolver is not working.

**

We are using Nginx nginx/1.27.5. Open source

Deployment environment: Prod

I will appreciate if anyone can help on this, Thanks in advance.

Heya @ramkr123! Can you share your access and error logs when a timeout occurs? Are you using the official NGINX ECR image or are you building your own variant?

Using a full domain name within proxy_pass is totally fine if you define a resolver, which you do. Based on what you are saying I think this is more likely an AWS networking issue and/or the container getting degraded over time for some reason.

1 Like

Hi Alessandro

Error Log

logRecord.body:{“log”:“2025/07/05 21:30:02 [error] 20#20: *910462 upstream timed out (110: Connection timed out) while connecting to upstream, client: 10.1.52.152, server: app1.com, request: "GET /url1 HTTP/1.1", upstream: "https://10.1.49.44:443/url1”, host: "app1.com"
",“stream”:“stderr”,“time”:“2025-07-05T21:30:02.944451431Z”}

This article also states the same issue that we also faced where the resolver is added but dynamic variable is not added.

Mod’s note: The user who posted this suggestion (@ReckEco) turned out to be a bot writing AI suggestions. I have restored the post to maintain the topic flow, but that’s why it shows as being authored by the forum “system”.

The NGINX timeout issue could be due to static DNS resolution in your proxy_pass directive. To resolve this, use a variable for the domain name in proxy_pass to allow dynamic DNS resolution. Here’s an example:
location ~ ^/(url1|url2)$ {
set $backend “appl2-prod.bytemark.co”;
proxy_pass https://$backend;
proxy_set_header Host $backend;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

@ReckEco ’s solution can solve this problem, but it will make it impossible to use long connections. I recommend the following solution.

resolver 169.254.169.253 valid=30s;
upstream appl2-prod-upstream {
    zone upstreams 64k;
    server appl2-prod.bytemark.co:443 resolve;
    keepalive 32;
}
server {
    ...
    location ~ ^/(url1|url2)$ {
        proxy_pass https://appl2-prod-upstream;
        proxy_set_header Host appl2-prod.bytemark.co;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_Header Connection keep-alive;
        proxy_http_version 1.1; 
    }
    ...
}