nginx,

Nginx server blocks processing order of priority

May 07, 2023 · 1 min read · Post a comment

In the previous post Multiple ways to test a Nginx location match I wrote about how to test the location match but here’s the thing. You need to know the order first before testing anything, right?!

Prerequisites

  • Nginx

Solution

The processing order of priority when dealing with Nginx server blocks is the following one:

  1. The exact names being processed first.
  2. Longest wildcard names starting with an asterisk * e.g. *.devcoops.com.
  3. Longest wildcard names ending with an asterisk * e.g. preprod.*.
  4. First matching regular expression (in order of appearance in a config file).
  5. The default server block.

Official Nginx docs: Server names.

Conclusion

In case you face any issues, feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.