Nice nginx features for developers

submited by
Style Pass
2021-06-05 07:30:03

A lot of people use nginx as a web server and fallback for something like haproxy or traefik for service routing. But you can use nginx for that too! In my experience nginx provides rich and flexible ways to route your requests. Here are few things that worked well for me when I was wearing a developer hat.

First, let’s look at the simple config that just forwards requests from http://proxy.local/ address to a single http://backend.local:10000.

Then you declare entrypoint with a server and location. Given that it’s nginx you can go crazy with regexp location matching and stuff but it’s not what is required in the case of service routing.

If your service needs active/passive configuration where one server is the main for requests handling and the other is a backup then you can configure it like this:

By default, server is marked as unavailable after 1 connection error or timeout. This can be tuned with max_fails option for each server in an upstream group like this:

Leave a Comment