Best practices for configuring a VPS for web hosting

I’m just getting started with Nix. Most of the resources I’m seeing are targeting desktop setups, and I can’t find much info about how are people using NixOS for web hosting?

What I’d like to do is run several node apps or docker containers with nginx acting as a reverse proxy on a VPS. What are the best practices? Do I need the home manager for instance? How would a configuration folder structure look like?

Any tips or links to existing tutorials would be appreciated!

Broadly, this is the subject matter of the excellent book NixOS in production. I think it would give you a very good foundation to start; it walks the reader through deploying NixOS to an AWS instance with ssh and nginx-fronted static site serving.

1 Like

No reason for home manager. Just to confirm, you’re talking about NixOS, right? Not something like Nix package manager on Debian?

I’d start with these:
Docker
NixOS Containers
Nginx
Firewall

If there’s no NixOS image for your VPS you should take a look at nixos-anywhere.

1 Like

NixOS, yes.
Are there any benefits to running NixOS containers vs Docker?
I’d love to see some basic configs as examples. Are there any?

It all depends on your usecase.
Pros:

  • leverages the nix store for much smaller containers
  • can be managed right inside your nix config, you can freely pass config from the host to the container.
  • you get the whole suite of nix services, nix packages, and systemd features

Cons:

  • By default, sandboxxing is weaker
  • No networking magic for groups of containers. You need to set that up manually

Depends who you ask:

  • uses systemd’s container features
  • updates only when you update your host system

I think that wiki page has an example of a webserver running apache and a firewall, ergonomically it feels more like LXC than Docker because you could have multiple programs/services in a single container.

There’s nothing wrong with using both.