Nginx – Nginx Mirroring Without Mirror Module

mirroringnginx

It has happened that someone that is not at my company anymore decided to manually compile nginx without knowing exactly what he was doing and put it into production.

Now we cannot add modules and we are in a situation where we can't just turn off the nginx and start over with a fresh instance because it would disrupt customer's experience (because it is in production).

In order to get closer to the point (where we can substitute this nginx instance with a fresh and new one), we would like to implement mirroring. Again, we cannot install the mirror module right now.
We have to do it in some other way.

I don't know anything about nginx, but I am the one that always wants to learn and like to go explore the web to discuss things with people.

Basically, we have a nginx that works as a reverse proxy. Requests that are sent to url/apis* are redirected to an internal API server. For testing purposes we need to mirror this traffic to another server. Someone at work came up with this solution, using post_action.

location ~* /apis*$ {
  proxy_pass http://api_server/$1;
  proxy_set_header Host      $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_pass_request_headers      on;
  gzip "on";
  keepalive_timeout 10;
  post_action @mirror_test;
  }

  location @mirror_test{
    proxy_ignore_client_abort on;
    proxy_pass http://test_api_server/$1;
  }
}

Now, this solution does mirror the traffic correctly, but, we are not sure if the responses are ignored. Reading on the mirror module documentation, it says that the mirror subrequest responses using that module are ignored, and we would like to obtain the same behavior. Responses to clients should only come from the main server (api_server) and not from the mirrored one (test_api_server).

So, in this configuration, are the responses coming from the mirrored server ignored or not?

Best Answer

You can upgrade nginx without dropping a single client connection: https://www.digitalocean.com/community/tutorials/how-to-upgrade-nginx-in-place-without-dropping-client-connections

Update: The following text hits at your question in the comments:

The first step to gracefully updating our executable is to actually update your binary. Do this using whatever method is appropriate for your Nginx installation, whether through a package manager or a source installation.

Thus you can do a clean installation of the sources using whichever module you want to include or exclude and then use that binary for the upgrade process.