simon-says.info

nginx configuration is horrible - Simons Blog

1/30/2026Updated 4/2/2026

Excerpt

So recently I was tasked with moving a webserver configuration from Apache to nginx. ... While porting the configuration over from Apache, I wanted to clean things up a bit and make things easier to configure. At this point nginx showed its ugly side. The configuration syntax makes it seem like it's a programming language, but it's not. It has similarities, but I've since learned to ignore that bit in my brain that says: "Look, it has if's and variables with dollars, it's just like PHP!" and tell it: "No, it's still a configuration language. Not a programming language". Anyway, here are some oddities which I've come across: ## There are no AND/OR operators You have comparisons, but you can't combine them in any way. There is no `||` or `&&` so you have to write multiple if-statements: … ## You can't nest if-statements Not possible. Nginx will complain about an "if" not being valid inside another "if". Here's a workaround: … Yes. That's string concatenation... If no variable matches, $check is "0", if only $var1 matches its "1", if only $var2 matches its "10". If both match, it's "11". Stupid? Yes. But it's one of the recommended ways to do it. And just wait, it gets worse. … ## Strings can't be used as Regex Assume you have a regex in a string. You want to match something against that string. That doesn't work, it will just never match. At least with all the issues above, the configtest `nginx -t` will fail, but here it just silently doesn't work. … ## Don't count on ChatGPT to help you It will happily generate nested ifs, hallucinate escape sequences which don't exist, try to match against regexes in variables, etc. Basically all the things mentioned above.

Source URL

https://simon-says.info/2026/2026-01-30-nginx-configuration-is-horrible

Related Pain Points