How to force Nginx to use Upstream even if it fails?

2 min readSep 27


Using Nginx as a reverse proxy in a containerized environment might be challenging.

Photo by Nathan Dumlao on Unsplash

Consider the following cluster topology:

Consider you have the following scenario

Your cluster serves content for and

Requests for are failing due to an internal problem in the container.

However, everything is fine with the’s containers.

Because the requests for are failing, Nginx will mark the upstream IP addresses as failed and cease sending requests to those IP addresses.

Nginx will show the “502 Bad Gateway” message to the users. can no longer be reached either.

Because of a problem with the container, it is no longer possible to reach Because they are both behind the same IP addresses, and Nginx has marked those IP addresses as failed.

We need to force Nginx to send network traffic to upstream IP addresses no matter what the state of those IP addresses is.

We can force Nginx using these upstream parameters:


This is an example of a Nginx configuration:

upstream mycluster {
server fail_timeout=0 max_fails=0;
server fail_timeout=0 max_fails=0;
server {
listen 80;
server_name _;
location / {
proxy_pass http://mycluster;
proxy_set_header Host $http_host;

These settings are dangerous. Even if the container is unable to accept new connections, it will continue to receive requests.

P.S.: This post is based on an actual production problem.