I wrote an nginx module (in C) over the weekend, and I was pleasantly surprised how nicely structured, simple, and well-organized the nginx codebase is. I wrote a module that filtered HTTP requests, inspected one HTTP header, and generated one other HTTP response header. The module offers nginx directives and nginx HTTP-level variables for configuration, customization, and debug logging. All told, it took ~500 lines of C and I could re-use a lot of nginx utility functions, and the structure of my module was easy-to-read. As someone who hadn’t written C in several years (I usually write Python), I was impressed!
I’ve been using Nginx for years. I really like it, mostly because it is so much more resource efficient than Apache.
Not to mention the configuration is way easier to manage and write.
Agree 100%. It was a total breath of fresh air after years of accumulating Apache pain.
Building on nginx, if anyone hasn’t come across OpenResty it’s well worth looking into - it embeds LuaJIT into nginx and exposes loads of nginx API to Lua so that you can basically script the web server & proxy/balancer functionality, but also write complete applications in it. Lets you do complex stuff simply, neatly, precisely and at a high level of performance. Comes as a bundle of nginx modules that you can use and then pull in Lua libraries using luarocks or its own package manager. One of the best web server/application models I’ve had the pleasure of using - and wouldn’t be possible without nginx.
+1 for OpenResty. I’m currently experimenting with that and HHVM to replace our NGINX+PHP-FPM stack at work. What I love is that you can write dynamic configuration files (like having a generic logging block with a hostname variable appended to the file names).
But it’s getting harder and harder to write as more features are added, more defaults become out of date, and so on.
For the same reason I’ve been moving to using the golang stdlib to write custom load balancing behaviour. Having a real language is a real boon.
I don’t actually care about the resource efficiency. I use it because the configuration makes sense.
[Comment removed by author]
It’s “Engine-X” - https://www.nginx.com/resources/wiki/community/faq/
Given the benefits and that it’s so easy to migrate from Apache to Nginx I’m surprised this isn’t way more divergent by now. Other than legacy support slash too lazy to change, are there any pros to Apache I’m unaware of?
Apache just works fine and is supported by Red Hat? I guess that covers also some of the “not switching” crowd.
Personally, I never saw the need to change to nginx, seems just as big and bloated as Apache, and not that easy to configure if you want to have a secure php-fpm deployment. If I’d switch then to something like OpenBSD’s httpd.
Nginx did not support loading modules at runtime until recently. In addition, there exists an Apache module for basically anything you could possibly want to do.
What do people think about Apache’s .htaccess, and the fact that nginx doesn’t have it? I know that converters exist; nginx itself provides a writeup explaining why you shouldn’t want it; I have my own ideas but I’m just curious what people here have to say about it.
It’s a security hazard and an IOPS slaughterfest
I understand why they exist but I don’t like them. We can do better than having to read and parse a file on each request.