this post was submitted on 26 Jul 2024
162 points (94.0% liked)

Selfhosted

40183 readers
515 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules:

  1. Be civil: we're here to support and learn from one another. Insults won't be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it's not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Don't duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).

  6. No trolling.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 1 year ago
MODERATORS
 

I see so many posts and people who run NGINX as their reverse proxy. Why though? There's HAProxy and Apache, with Caddy being a simpler option.

If you're starting from scratch, why did you pick/are you picking NGINX over the others?

top 50 comments
sorted by: hot top controversial new old
[–] [email protected] 3 points 3 months ago

There's a lot of good resources for Nginx, it's fast (faster than Caddy), and has a ton of features, so you can use it for pretty much anything HAProxy, Apache, or Caddy can do, and not sacrifice much in performance.

That said, I mostly use HAProxy and Caddy. Here's my basic setup:

  1. HAProxy at the edge VPS - routes requests to machines based on SNI
  2. WireGuard VPN - connects my internal devices to my VPS
  3. Caddy in Docker - runs on internal network on my NAS/homelab - manages LetsEncrypt renewals and reverse proxies to internal Docker network
  4. Nginx in Docker - FE for NextCloud; this simplifies things so all my TLS is handled in one place, and Caddy doesn't need to touch files

I use a local DNS server on my router so my domains can route directly to Caddy instead of going over the internet when on my network, otherwise I may just have HAProxy handle LetsEncrypt certificates.

From what I can tell, Nginx is a little more efficient than Caddy, but Caddy is plenty fast for my needs. I'm considering switching from NextCloud to the new ownCloud Infinite Scale, and if I do, I'd ditch nginx completely.

[–] [email protected] 3 points 3 months ago

Nginx "just works(tm)" had never got into the way, its been rock solid and has not changed significantly over the years.

Why would I need something else?

[–] [email protected] 1 points 3 months ago

Often I already have nginx running for serving some static content anyway.

Otherwise, I’m traefik all the way.

[–] [email protected] 2 points 3 months ago

Nginx was the easiest to setup for me at the time and I've no reason to fix what isn't broken.

[–] [email protected] 6 points 3 months ago

Caddy's developer gives me the ick. He's way too pompous in PRs on GH. nginx is just a constant -- it does exactly what you need to and does it well.

[–] [email protected] 16 points 3 months ago
  • simple config & setup
  • good performance
  • popular/packaged by every single distro
  • just works
[–] [email protected] 5 points 3 months ago* (last edited 3 months ago) (1 children)

TLDR: probably a lot of people continue using the thing that they know if it just works as long as it works well enough not to be a bother.

Many many years ago when I learned, I think the only ones I found were Apache and IIS. I had a Mac at the time which came pre installed with Apache2, so I learned Apache2 and got okay at it. While by release dates Nginx and HAProxy most definitely existed, I don't think I came across either in my research. I don't have any notes from the time because I didn't take any because I was in high school.

When I started Linux things, I kept using Apache for a while because I knew it. Found Nginx, learned it in a snap because the config is more natural language and hierarchical than Apache's XMLish monstrosity. Then for the next decade I kept using Nginx whenever I needed a webserver fast because I knew it would work with minimal tinkering.

Now, as of a few years ago, I knew that haproxy, caddy, and traefik all existed. I even tried out Caddy on my homelab reverse proxy server (which has about a dozen applications routed through it), and the first few sites were easy - just let the auto-LetsEncrypt do its job - but once I got to the sites that needed manual TLS (I have both an internal CA and utilize Cloudflare' origin HTTPS cert), and other special config, Caddy started becoming as cumbersome as my Nginx conf.d directory. At the time, I also didn't have a way to get software updates easily on my then-CentOS 7 server, so Caddy was okay-enough, but it was back to Nginx with me because it was comparatively easier to manage.

HAProxy is something I've added to my repertoire more recently. It took me quite a while and lots of trial and error to figure out the config syntax which is quite different from anything I'd used before (except maybe kinda like Squid, which I had learned not a year prior...), but once it clicked, it clicked. Now I have an internal high availability (+keepalived) load balancer than can handle so many backend servers and do wildcard TLS termination and validate backend TLS certs. I even got LDAP and LDAPS load balancing to AD working on that for services like Gitea that don't behave well when there's more than one LDAPS backend server.

So, at some point I'll get around to converting that everything reverse proxy to HAProxy. But I'll probably need to deploy another VM or two because the existing one also has a static web server and I've been meaning to break up that server's roles anyways (long ago, it was my everything server before I used VMs).

[–] [email protected] 3 points 3 months ago

Thanks for the comment, that was a good read

[–] [email protected] 1 points 3 months ago

The only reason that I tend to use it is because of the included webserver. It's not bad but the paywalling of functionality needed for it to be a proper LB left a bad taste in my mouth. That and HAProxy blows out of the water in all tests that I've done over the years where availability is at all a concern. HAProxy also is much more useful when routing TCP.

[–] [email protected] 6 points 3 months ago (1 children)

Caddy certainly was the easier option but it's as complex as nginx now and id argue it's hard to to use.

[–] [email protected] 1 points 3 months ago

Why do you say that?

I've used both plenty and only once I thought Caddy was harder: caching. It requires you to install a plugin that also doesn't have the easiest of configs. I think there's a new and simpler one nowadays, but haven't tried it yet.

I now use Caddy by default for everything new I make/host.

[–] [email protected] 2 points 3 months ago* (last edited 3 months ago) (1 children)

I use Traefik because it solved a problem with the static configuration approach which Nginx had / still has.

In a scenario with multiple services behind Nginx, taking one down or replacing an instance is massive headache. I tried to script around it, but basically the Nginx container would choke on the fact that a service does not [yet / anymore] exist, and together with the docker networking stack it turned out to be an insurmountable problem.

Traefik otoh discovers services based on (in my case) labels on the docker containers running locally. And then updates the configuration on the fly.

Basically the static approach to configuration resulted in massive headache when I needed to enable zero downtime deployments and updates behind Nginx. And Traefik handled it perfectly without dropping a single request.

Nowadays I manage my dynamic configuration with ansible and update the values in for the file-based configuration provider with a playbook. I don't need a UI to manage my inventory, I use ansible for that. Traefik handles the rest perfectly.

[–] [email protected] 1 points 3 months ago

Completely agree, which is why I do the same.

Additional bonus: proxies that interact with the docker API directly (I think also caddy can do it) save you from exposing the services on any port at all (only in the docker network). So it's way less likely to expose a port with a service by mistake and no need for arbitrary and unique localhost ports.

[–] [email protected] 7 points 3 months ago* (last edited 3 months ago)

Why not? Why should I use Apache instead of Nginx? I don't know about Caddy, Nginx is simple enough not to care about simpler solutions. But in general, I know Nginx and it does the job.

[–] [email protected] 23 points 3 months ago (1 children)
[–] [email protected] -1 points 3 months ago (1 children)

Why is their question, so why is it pretty good?

[–] [email protected] 17 points 3 months ago (3 children)

Nah, their question is why do so many people use it. And the answer is because it's pretty good.

[–] [email protected] 1 points 3 months ago

You want to play this game?

I can create new posts all night long

[–] [email protected] 1 points 3 months ago

Very helpful

[–] [email protected] 6 points 3 months ago
[–] [email protected] 14 points 3 months ago* (last edited 3 months ago) (1 children)

Security

Caddy is good but it tried to do to much. This means that security bugs could be way more common. It has been audited by outside people and the issues they found were fixed but I am will very doubtful that it is secure yet

[–] [email protected] 1 points 3 months ago

I think security is a fair point, given caddy's younger age compared to nginx, but I wouldn't say it tried to do too much.

[–] [email protected] 54 points 3 months ago (1 children)

It just works and it's in every distros default repo, it's pretty easy to set up and can be a webserver for static files, PHP sites, etc.. It can be a reverse proxy for HTTP(s) traffic or just forward TCP/UDP.

There's also endless documentation out there for how to do something in nginx.

HAProxy is a nightmare to use in my experience. It just feels so clunky and old.

Caddy is nice, but downloading and updating it is a pain because you need modules that aren't included in the repo version.

[–] [email protected] 13 points 3 months ago (1 children)

Right there with you on “just works,” as well as the simple fact that the config snippets you need are readily available - either in the repo of whatever you’re putting behind the proxy, or elsewhere on the internet.

I consistently keep in mind that it’s ultimately an RU product, of course. But since it’s open source and changes relatively infrequently, that’s mitigated to a large degree from where I sit.

Nothing against Caddy, though Apache gets heavy quickly from a maintenance standpoint, IMHO. But nginx has been my go to for many, many years per the above. It drops into oddball environments without having to rip and tear existing systems out by the roots, and it doesn’t care what’s behind it.

Ages ago, I had a Tomcat app that happened to be supported indirectly by an embedded Jetty (?) app that didn’t properly support SSL certs in a sane way on its own.

That was just fine to nginx and certbot, the little-but-important Jetty app just lived off to the side and functionally didn’t matter because with nginx and certbot, nothing else gave a crap - including the browser clients and the arcane build system that depended on that random Jetty app.

[–] [email protected] 3 points 3 months ago

Nginx is owned by F5 now which is an American company so it's not RU anymore

[–] [email protected] 2 points 3 months ago

I learned nginx when I was hosting websites. I had it set up and running when it was time to add reverse proxies into my setup. It didn't take much more from the virtual hosts I was already using.

Now, I don't host many individual sites anymore and haproxy has a plugin on my firewall for the handful of services I run now.

[–] [email protected] 10 points 3 months ago (7 children)

Counter question: Why does everyone call it "engine X" and not "enjinx", which would be the way cooler pronunciation?

[–] [email protected] 1 points 3 months ago

I always did? A friend pointed out to me once the "correct" pronunciation. I like this way more.

[–] [email protected] 2 points 3 months ago

It's actually n-jynx duh

[–] [email protected] 1 points 3 months ago

I always said "in GIN icks" (gin like the alcohol) based on someone else's pronunciation years ago. I never realized it was meant to have anything to do with "engine" as a result.

[–] [email protected] 15 points 3 months ago* (last edited 3 months ago)

Directly from the nginx home page:

nginx [engine x] is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP/UDP proxy server, originally written by Igor Sysoev.

[–] [email protected] 3 points 3 months ago (1 children)

oh I've only ever read it, never heard it pronounced, do people really pronounce it engine X?

[–] [email protected] 7 points 3 months ago

That is the way it’s pronounced, yes.

[–] [email protected] 5 points 3 months ago

I call it N Jinx. Always have and I’ll never be convinced otherwise that it’s not.

[–] [email protected] 2 points 3 months ago

Huh. That is way cooler

[–] [email protected] 13 points 3 months ago (2 children)

Traefik + CrowdSec + Authelia ftw

[–] [email protected] 2 points 3 months ago

I used to use traefik back when it was new and less complex and the 2.0 complexity forced my hand to drop it for my homelab.

[–] [email protected] 9 points 3 months ago* (last edited 3 months ago) (2 children)

Traefik gang here 👊 !

But only because it works so easily with docker !! I remember a time where I though that you need a diploma and read/learn/understand a 10000 page dictionary to make nginx work properly.

Also hated the syntax of nginx... It can look so ugly and gibberish :/.

But I do believe Nginx is superior and more mature in many more aspects than Treafik. Still, Traefik is a breeze and is in IMO way easier to configure with docker than Nginx.

[–] [email protected] 3 points 3 months ago

I use Traefik as my main reverse proxy as well for the same reason—container niceties. But then I actually also use nginx.. inside container images, like for containers that just serve static files for example.

Use the right tool for the job!

[–] [email protected] 3 points 3 months ago

Yeah it's Traefik for me as well! Heavy docker user, of course - it's nice just tossing some labels into my Portainer stacks and letting Traefik figure it out. If I wasn't so invested with containers I'd be using nginx.

load more comments
view more: next ›