No nginx basic auth with either network or cookie set

For an internal tool, we’d like to allow access if you either coming from one of our office networks or you have a certain cookie set. If both are not satisfied, just show the usual basic auth dialog. And set that cookie, once you were allowed to access the page.

We wanted to do that in nginx and not the tool itself, as it looked like easier to do, especially since the tool didn’t have any authentication at all yet. Unfortunately it wasn’t that straight forward, but we found a working solution and wanted to share that.

Hope it helps anyone and saves them some time.

This was of great help, thanks!!

Have you ever tried to port it to Apache? (Haven’t worked with Nginx yet :( )

Leave a Reply