7 ms·
Nginx Unit: open-source, lightweight and versatile application runtime
- ngrilly 2y agoNeat! What is the benefit of using this over "standalone" nginx? The HTTP API enabling configuration change at runtime without downtime (like Caddy)? No need for a process supervisor like supervisord or systemd as nginx Unit is managing the backends?
- supriyo-biswas 2y agoFor me I'd rather ship a single binary with PHP support in it when using containers.
- la_fayette 2y agoCan you elaborate on that? Especially, where is the php runtime and the webserver?
- 9dev 2y agoIt’s pretty much like Caddy vs. nginx: Language runtime, static asset serving, TLS, routing and so on bundled in a single package. That makes it very easy to deploy a container, for example. Thinking of a typical PHP app, which exposes both dynamically routed endpoints and static asset. With a traditional setup, you’d let nginx handle all paths as static assets and fallback to the index.php file to serve the app. When you package that as a container, you’ll either have to use separate PHP-FPM and nginx containers, or run two processes in a single container. Both of which is not ideal. And it gets ever more complex with TLS, and so on. Using unit or caddy, you can simplify this to a single container that achieves it all, easily.
- SahAssar 2y agoWhat is caddys language runtime? Which languages does it support? Or are you thinking of the frankenphp plugin?
- 9dev 2y agoCaddy can either use something sophisticated like FrankenPHP, which I very much look forward to using soon now that it seems stable, or a regular old FastCGI SAPI.
- SahAssar 2y agoBut nginx also supports FastCGI, and you need to run the FastCGI server as a separate process (like php-fpm), right? I don't see how caddy (without stuff like frankenphp) is any closer to a complete single binary reverse-proxy AND language runtime than nginx.
- chuckadams 2y agoUnit has its own SAPI for PHP and executes it directly, no php-fpm needed. I’m using it to serve Wordpress right now, works pretty well.
- SahAssar 2y agoRight, but the parent comment seemed to imply that the same was true for caddy. I was asking what caddys language runtime was (besides via plugins like frankenphp)?
- chuckadams 2y agoPlugins would be it, so you could say Go is Caddy's runtime. Which is of course duh, but since the official mechanism to extend it is by statically compiling in go code, it's also accurate. It's not like nginx and apache are that much different, their "language runtimes" also boil down either to extensions linked into the server or proxying to a backend through another protocol like FastCGI. Caddy supports fcgi out of the box, even using PHP's default settings with one line of config, but I'm not a big fan of php-fpm, and I like having just one daemon to supervise.
- 2y ago
- attentive 2y agoIt's an app server. It can run your asgi or wsgi app.
- callahad 2y agoExactly, they're complements: you'd deploy your application on Unit and put that behind NGINX or another reverse proxy like Caddy or Traefik. Unit can serve static assets, directly host Python / PHP / WebAssembly workloads, automatically scale worker processes on the same node, and dynamically reconfigure itself without downtime. Unit cannot do detailed request/response rewriting, caching, compression, HTTP/2, or automatic TLS... yet. ;)
- geenat 2y agoAt this point I'd rather be good at Caddyfile and have a project folder of: /home/me/project/caddy /home/me/project/Caddyfile No sudo, no config spew across my filesystem. Competition is good, and I had a lot of fun with nginx back in the day but it's too little too late for me.
- kaptainscarlet 2y agoCaddy sounds like the go to tool for people who care a lot about getting things done. It's time for me to try it.
- bavell 2y agoEh, it's a bit over hyped imo although I do like the config format and built-in acme. My production clusters all run nginx though and give me minimal fuss with a lot of flexibility.
- diarrhea 2y agoA coworker of mine dislikes it as it bundles everything into a single binary. For example, to have ACME DNS-01 challenges for certificate issuance working, I need to compile in a Google DNS-specific plugin. But then it... just works. Try the same with most other web servers/proxies and you're in for a world of pain. Having this much functionality bundled into a single binary is as much a curse as it is a blessing. That said, having your own little 'Cloudflare Workers' in the form of Nginx Unit with wasm sounds great. Not sure Caddy can do that.
- TheCapeGreek 2y agoFor me, the promise of Caddy and especially tools around it like FrankenPHP make the "everything in a single binary" idea the MORE enticing option, not less. Sure we already have repeatable infrastructure, containers, etc. but I also love the idea of just building and shipping a PHP app binary that includes the webserver. It makes server provisioning even less of a priority, especially if I have reasons to not use serverless or PaaS tools.
- 2y ago
- simonw 2y agoFor some reason I had a thought lodged in my head that Unit wasn't open source, but I just checked their GitHub repo and it's been Apache 2 since they first added the license file seven years ago. I must have been confusing it with NGINX Plus.
- rvnx 2y ago“Oops, sorry, thank you for letting us know, we will change that to the proprietary license instead”
- vdfs 2y agoUsually it's done on purpose, they wait until it get very popular and used everywhere before pulling the carpet
- callahad 2y agoI wouldn't bet on that. :) F5 isn't the most visible corporation in terms of grassroots engagement, but NGINX itself has remained F/OSS all these years and newer projects like the Kubernetes Ingress Controller [0], Gateway Fabric [1], and NGINX Agent [2] are all Apache 2.0 licensed. Just like Unit. We do have commercial offerings, including the aforementioned NGINX Plus, but I think we've got a decent track record of keeping useful things open. [0]: https://github.com/nginxinc/kubernetes-ingress https://github.com/nginxinc/kubernetes-ingress [1]: https://github.com/nginxinc/nginx-gateway-fabric https://github.com/nginxinc/nginx-gateway-fabric [2]: https://github.com/nginx/agent https://github.com/nginx/agent
- casperb 2y agoI tried a setup with Nginx Unit and php-fpm inside a Docker container, but the way to load the config is so combersome I never was confident to use it in production. It feels like I am doing something wrong. Is there a way to just load a config file from the filesystem?
- jonatron 2y agohttps://unit.nginx.org/howto/docker/#apps-in-a-containerized-unit https://unit.nginx.org/howto/docker/#apps-in-a-containerized... > We’ve mapped the source config/ to /docker-entrypoint.d/ in the container; the official image uploads any .json files found there into Unit’s config section if the state is empty.
- casperb 2y agoI saw that, but I do like to make my own container. So I did roughly the same steps as they do. But it feels complicated.
- jonatron 2y agoCan you copy the official image's script? https://github.com/nginx/unit/blob/0e79d961bb1ea68674961da1703ffedb1ddf6e43/pkg/docker/docker-entrypoint.sh https://github.com/nginx/unit/blob/0e79d961bb1ea68674961da17...
- gawa 2y agoThe docs mentions: > The control API is the single source of truth about Unit’s configuration. There are no configuration files that can or should be manipulated; this is a deliberate design choice (https://unit.nginx.org/controlapi/#no-config-files https://unit.nginx.org/controlapi/#no-config-files) So yeah, the way to go is to run something like `curl -X PUT --data-binary @/config.json --unix-socket /var/run/control.unit.sock http://localhost/config/ http://localhost/config/` right after you start your nginx-unit. The way to manage a separate config step depends on how you manage to run the process nginx-unit (systemd, docker, podman, kubernetes...). Here's an example I found where the command is put in the entrypoint script of the container (see toward the end): https://blog.castopod.org/containerize-your-php-applications-using-nginx-unit/ https://blog.castopod.org/containerize-your-php-applications...
- RantyDave 2y agoDjango without gunicorn? I’ll give it a go…
- move-on-by 2y agoI’ve largely enjoyed gunicorn. What do you dislike about it?
- DataDive 2y agoI largely agree here that of all the components in a stack, unicorn seems to be the least troublesome and almost invisible. I have never had a problem that I would have traced back to gunicorn not working ... On the other hand not having to run gunicorn as another separate service might be an advantage.
- RantyDave 2y agoOh nothing really, it's just another cog is all. I'm running nginx because there's some things I want to serve statically (and it does a couple of other boring tasks really well too), so if I could just point it at the environment and tell it to go for it then it would just be a bit less messing around. I'm connecting nginx to gunicorn through a unix socket too and found that to be a bit of a pain.
- anentropic 2y agoI'm wondering what are the pros and cons of that vs this Years ago every website needed Apache or Nginx, then lately I've hardly used it at all... usually have a container with gunicorn behind a load balancer that is part of the cloud platform It's easy to see how to get Nginx Unit working, but not sure exactly how it fits into the utility picture vs other options
- teitoklien 2y agoNginx is a reverse proxy, it can work as the load balancer, the static asset server, a response caching server, an authorization server, HLS streaming server, etc. Nginx has a lot of usecases in one package, most larger companies and more technical workplaces, use Nginx or similar alternatives. Nginx Unit typically is meant for unifying the entire application space of multiple programming languages served by 1 Server (which also acts as a static server) So serving golang, python, php code and application all under 1 single wsgi/asgi application server called nginx unit and be able to dynamically change its routes with api calls too. This allows you to have 1 root process in a docker container to control your python fastapi or golang api processes, without needing 1 container for nginx and 1 container for Python/Golang process or a supervisord like init system controlling 2 or more processes inside 1 container Everything is under nginx unit and nginx unit is being triggered as the main process inside the container. Moreover it is also much much much more faster in terms of response time than most language dependent application servers like gunicorn/unicorn for python3, etc [1] [1](https://medium.com/@le_moment_it/nginx-unit-discover-and-benchmark-part-3-c38661194cd0 https://medium.com/@le_moment_it/nginx-unit-discover-and-ben...)
- random_savv 2y agoHow does this compare to OpenResty? Could it somehow help with OIDC support (e.g. by integrating a relevant nodejs lib)?
- pjmlp 2y agoThere is a certain irony that after the application servers bashing phase, a decade later everyone is doing their own version.
- throwaway894345 2y agoWhat is an application server exactly and who besides nginx is building one?
- pjmlp 2y agoApache with mod_tcl, mod_perl, mod_php, Websphere, JBoss (now Wildfly), Payara, IIS/.NET, Erlang/BEAM... Basically a full stack experience from programming language, web framework and networking protocols, possibly with a management dashboard. As for who is building one everyone that is now trying to sell the idea of packaging WebAssembly into containers, deploying them into managed Kubernetes clusters, or alternatively cloud managed applications, like Vercel, Nelify, Azure Container Apps, Cloud Run,....
- anentropic 2y ago> everyone that is now trying to sell the idea of packaging WebAssembly into containers, deploying them into managed Kubernetes clusters, or alternatively cloud managed applications Does Nginx Unit really fit into this picture though? Is there a place for an all-in-one app server in that scenario, I would have thought they want each component to be separated (wasm host, load balancer, etc etc) for commoditisation and independent scaling of different layers (This is not a criticism in form of a question... I am honestly curious)
- callahad 2y agoAbsolutely keep your load balancer for multi-node scaling, but how are you going to run you WebAssembly workloads within a given node? Unit can do that. Or what if you have a single logical service that's composed of a mix of Wasm endpoints and static assets augmenting a traditional Python application? Unit pulls that all together into a single, unified thing to configure and deploy. If you're writing Node, Go, or Rust you haven't had to think about application servers for a long time. Folks writing Python and PHP still do, and WebAssembly will require the same supporting infrastructure since Wasm -- by definition -- is not a native binary format for any existing platform. :)
- xandrius 2y agoI read this and expected some sort of unit testing for nginx configurations. I'd love to have something like that: provide a configuration and automatically check all the paths that the configuration enables. Maybe throw in some LLM for some comments and tips to improve performance/security.
- nginxdud 2y agoAnother dud from the people that bought stolen code. Nginx is awful, archaic software.
- victorbjorklund 2y agoWhat do you use instead?
- OneOffAsk 2y agoNginx is a state machine that efficiently handles lots of L4-L7 protocols. Seems weird to feel any emotions about it.
- g15jv2dp 2y ago[flagged]
- fastball 2y agoWe've been using Nginx Unit in production for a Python backend for about a year now and it's been working pretty well. Some thoughts in no particular order: - "Nginx Unit" is an annoying name to google when you have a problem. You get a lot of nginx results that are of course completely irrelevant to what you're looking for, as there is zero actual overlap between the two things. Using quoted search terms is not sufficient to overcome this. - When it works, the all-in-one system feels great. - However sometimes the tightly-coupled nature can be slightly annoying. For example, they publish packages for the various runtimes (ours is python) in the various registries, but only for the "defaults. Concrete example: we are currently running Ubuntu 23.04 but wanted to upgrade to Python 3.12. However Nginx Unit only pre-packages a Python 3.11 package for unit on Ubuntu 23.04 as that is the system-included Python. Had to build our own support from source, which was fairly easy, but still more difficult than our pre-Nginx Unit infra, where all I would have to do is install Python 3.12 and I'm good to go (because the python runtime wasn't at all coupled with the webserver when our stack was Nginx + Python + Gunicorn) - I never properly benchmarked the two in a comprehensive comparison, but Nginx Unit is definitely faster than the aforementioned previous stack. I tested some individual routes (our heaviest/most important) and the speedup was 20-40%. - Even when I tell it to keep a minimum number of worker processes around, it kinda seems... not to? I haven't properly tested, but sometimes it feels more like serverless, where if I haven't sent a request in a while it takes a bit of extra time to spin up a process, but after that requests are snappier. Definitely need to properly investigate this but haven't gotten around to it yet. It might just be the difference between allocated memory and not rather than spinning up processes. - It's a shame it doesn't support SSL via Let's Encrypt out-of-the-box, like Caddy. To me that is the biggest (really only) missing piece at the moment. - I much prefer using the HTTP system to manage config than files, and find the Nginx Unit JSON config much, much more readable than either Nginx or Apache configs I've worked with in the past. I'd also give it a slight edge over caddy configuration. - That said, managing the config (and system in general) can sometimes be annoyingly opaque. The error messages are somewhat terse when updating config fails, so you need to dig into the actual logs to see the error. Just feels a little cat-and-mousey when you could just tell me what the error is up-front, when I'm sending the config request. In summary, overall I've liked using Nginx Unit, but wish they would: change the name to something less confusing, add built-in Let's Encrypt support ala Caddy, and make the errors and overall stack feel a little less opaque / black boxy.
- callahad 2y agoHi! I'm currently in charge of Unit. If you're using it, I'd love to chat with you to understand what sucks, what doesn't, and what's missing. I have my own ideas, but external validation is always nice. :) Contact info is in my profile.
- deleted 2y ago[deleted]
- Too 2y agoConfigured at runtime via REST?? What happened to infrastructure as code? Is this some property required for something like your primary load balancer entry point, that can never be restarted and can’t have rollout restarts?
- tomstoms 2y agoJust trying to understand. In the case of a Java app, would this replace tomcat or jersey or similar?
- ethagnawl 2y agoI'm no Java expert but I believe Unit would replace Tomcat, Jetty, etc. (i.e. the service handling HTTP requests) and would be responsible for running/managing/forwarding requests to a Jersey application.
- egberts1 2y agoOuch From NGINX Unit webite: "Also on Linux-based systems, wildcard listeners can’t overlap with other listeners on the same port due to rules imposed by the kernel. For example, :8080 conflicts with 127.0.0.1:8080; in particular, this means :8080 can’t be immediately replaced by 127.0.0.1:8080 (or vice versa) without deleting it first." Systemd (PID 1) also needs to start stopping their opening network sockets. In short, systemd now needs a systemd-socketd to arbitrate socket allocations. I am never a fan of PROM, firmware, nor PID1 opening a network socket; it is very bad security practice.
- ethagnawl 2y agoI've been dabbling with Unit when I've had some downtime over the last few days. It's definitely compelling and I quite like that it could potentially replace language-centric (I know there are ways to bend them to your will ...) web servers like gunicorn, unicorn, Puma, etc. It's also compelling that you can easily slot disparate applications, static assets, etc. alongside each other in a simple and straightforward way within a single container. As others have said and the team has owned up to, the current config strategy is not ideal but the Docker COPY strategy has been working well enough for my experiments. The other somewhat annoying part of the experience for me has been logging. I would want access logs to be enabled by default and it'd be great to (somehow) more easily surface errors to stderr/out when using the unit Docker images. I know you can tap into `docker logs ...` but, IMO, it'd be ideal if you didn't have to. It's possible there's a way to do this at the config level and I just haven't come across it yet. Also, and I know this is a bit orthogonal, but it'd be great if the wasm image exposed cargo, wasmtime, et al so you could use a single image to build, run and debug* your application. *This was a pain point for me and I got hung up on a file permissions issue for a few hours. On the whole, though, I think it's pretty compelling and I was able to stand up Flask, Django and Rust WASM applications in short order. I'm planning to add some documentation and publish the code samples as time permits.