I’ve been seriously tinkering with personal self-hosting for about five or six years now. Strictly speaking, the time I started managing my own VPS goes back even further. The original motivation was actually pretty simple: there were some services I used every day, like a password manager, music playback, note syncing, a personal website, code repositories and so on. So why not just deploy them myself? That way the data stays in my own hands, and I’m not pushed around by all kinds of platform subscriptions and price increases.
Looking back on these years, to be honest, self-hosting isn’t hassle-free. I have to maintain the system, back up data, keep an eye on security, and once in a while put out fires. But what I get back is also very clear:
- My data is fully under my own control
- I’m no longer pushed around by subscription prices
- I understand systems, networking and security a lot better
Now I run a dozen or so services on one server, and the cost is just the price of that one server. After canceling quite a few third-party subscriptions over the past two years, the overall cost may actually be lower when I do the math. For me, this “complex but under control” state feels more reassuring than depending on a pile of external services. Of course, this isn’t for everyone. I feel it suits people who have some technical background, enjoy tinkering, and are willing to put in time for stability and control. When all three come together in one person, this kind of setup fits.
Even now, I don’t think I’ve become any kind of “expert,” but my feelings about two things have grown stronger and stronger: security and how clean the server environment is. These are also the two main threads of this post. These two questions pretty much decide whether the services on your server can keep running stably over the long term. They also decide how much work it is when you need to migrate, for example when you switch to a cheaper or better VPS provider. (I’ve switched several times myself, and only settled down once I really couldn’t face moving again.)
The Rough Early Days
In the beginning, my approach was very basic. I installed services directly on the host, and then installed Nginx or Apache2 (httpd). For example, I used Nginx as a reverse proxy. The good thing about web servers like Nginx is that the config files can be split up, one per site, and services are told apart by domain name instead of port number, so everything looks neat and tidy. Back then I thought this setup was pretty elegant.
But as the number of services slowly grew, problems started to show up one by one. Some services needed specific versions of dependencies, and it was hard for me to install different versions of various libraries or databases in the same environment. Some left all kinds of temporary files in the system. Config files were scattered under /etc, data was in /srv, and logs were in /var. At first you could still remember “this belongs to that service,” but after a while it all got mixed up.
During this time, when I wanted to remove a service I no longer used, I wasn’t even sure I could remove it cleanly. This was especially true for services that come with a “one-click install script.” Installing them feels great at the time, but when you want to get rid of them, you find you have no idea what changes the script made back then, or how to undo them. It’s hard to know whether there are leftover configs or background processes, and you don’t even know whether deleting the wrong thing will break other services. This uncertainty is a risk in itself. For someone with a bit of a cleanliness obsession like me, it was deeply uncomfortable every time I thought about it.
The Containerization Phase
Later I moved almost all of my services into Docker. And these days I lean more and more toward containerizing every service or tool I use before deploying it. For services I really want to use but that don’t offer a standard containerized deployment, I just package them into containers myself and make my own containerized solution.
What really changed the experience wasn’t Docker itself, but Docker Compose. Containers basically shouldn’t be treated as “things to maintain long-term.” They can be deleted and rebuilt at any time, and you need to be aware of that. Early on, I thought Docker Compose files were a hassle. Why not just create a container with a command and let it run for a long time? Later, when I needed to update it, or when the service depended on several other containers underneath, the problems slowly showed up. If I had written the deployment down in a config file from the start, I could just run that file every time and reproduce the original deployment perfectly. I wouldn’t need to set up a bridge network, a hostname or a restart policy by hand. This saves a lot of time and energy, and the chance of making mistakes during configuration also goes way down.
Looking back now, I can say there are only three things that really need long-term maintenance:
- Service configuration (including version, network, storage and so on)
- Data (mainly volumes and other mapped directories)
- Deployment configuration (the various Docker Compose YAML files)
Whether I reinstall the system or switch to another machine, as long as these three are still there, the services can be cloned perfectly to the new place. And the host itself finally became “clean.” Its directories are no longer full of things you installed years ago and have since forgotten the purpose of. So at this stage, I created a separate Git repository to collect and manage the Docker Compose files for all the services I use. After a year with it, I feel this approach holds up in all kinds of situations.
One Service, One Database
This one is worth mentioning. For a long time, all of my services shared one database instance. Logically it looks very reasonable: it saves resources, the structure is simple, and management is centralized. But after maintaining it for a long time, you’ll find this is actually a very unfriendly design.
Every new service means another set of users, permissions and passwords. If you want to migrate a service, you have to carefully pull its database out. Once the database version is upgraded, every service has to share the risk. For people who aren’t familiar with a certain database, managing permissions and users is a headache. You have to use the command line or some database management tool to carefully keep each service’s users apart and keep their passwords safe.
Later I just did the opposite: each service gets its own database instance. That means each Docker Compose file has its own database service. After watching this for a long time, I found that for personal self-hosting, it’s not as “wasteful” as you might think. A database container usually only takes 100 or 200 MB of memory. On a VPS with 4 cores and 8 GB of RAM, or even 2 cores and 4 GB, or on a home server, that’s acceptable.
But what I get in return is very real. The services are fully isolated from each other, which improves security a lot, and I no longer have endless friction with permissions and compatibility. I can just pack up all the data and config in one go and take it with me, and each database only holds the data of its own service.
The Principle of Minimal Exposure
Early on, I exposed almost all of my services directly to the public internet, and protected them with a reverse proxy plus login:
- One Nginx Proxy Manager
- A public domain for every service
- Username/password protection at the application layer
Back then I also thought: “Every service has a username and password, so it should be fine, right?” Only later did I slowly realize that this was just fooling myself. As long as one service has a brute-force weakness, an authentication bypass or an RCE (remote code execution) vulnerability, an attacker may get access to the container or even the host. What first happened to me was with a GitLab instance I ran without a container. GitLab once had a serious remote code execution vulnerability, and I didn’t find out about it in time. Then one day I found that a trojan had been planted on my server, and I only knew because my cloud provider told me. If I had kept photos, videos or backups on that server back then, the result would have been a disaster.
Also, the security maturity of different services varies a lot, and their tech stacks vary widely. Some projects are still young, and their security thinking is far from mature. And I can’t watch every security advisory every day. Once one of these services has a vulnerability, or the frameworks or dependencies they use do, like the recent security vulnerabilities around the React stack, that service or those services can blow up in a short time. If containerization and isolation aren’t done well at that point, the attacker may get more than that one service. Quite possibly they get the whole machine. And then come the hidden trojan scripts or crypto-mining scripts.
This is also a core principle I came to later: if a service doesn’t have to be open to the public internet, don’t open it. Blogs and static pages don’t lose much if they get attacked, but things like notes, password managers and admin panels are a disaster if something goes wrong. So you need to take a good look at which services you’re exposing right now. From my own experience, the ones I feel safest about are static websites, or pages that are only generated from parameters with no database behind them. But there are a lot of services I want to use, so how do I expose some and not others? My current practice is to expose only the services that really need it to the public internet, like a static blog and a very small number of public services. Git repositories are kept private as much as possible, or only expose a read-only static view (through gitweb or cgit). Dynamic services, admin panels, notes, password managers and so on are never exposed directly to the public internet.
Deploying a Private VPN
Later I found that the key to solving this problem is a VPN. I deployed a private VPN on the server (WireGuard, for example) and put all private services into a network that can only be reached from the internal network. Only after I connect to the VPN and get a virtual internal IP can I reach these services, starting from that internal IP. The overall idea is:
- The VPN provides a virtual private subnet (like
10.8.x.x) - Docker internal services use another private subnet (like
172.x.x.x) - The two subnets can reach each other through routing
- The public internet can’t reach these services directly
What this step means is that I no longer need to design a separate “defense plan” for each service, because they’re not on the attack surface at all. Add a reverse proxy and DNS that only work inside the internal network, and the experience is actually better than on the public internet: clear domain names, stable services, and real peace of mind.
Internal Reverse Proxy and DNS Resolution
To improve the experience further, I deployed an internal Nginx container inside the internal network (under 172.24.0.0/16), completely isolated from the Nginx instance that serves the public (for example, 172.20.0.0/16). This internal Nginx instance is bound to a fixed private IP (for example, 172.24.0.2), and it only serves traffic that comes in through the VPN network.
flowchart LR
%% Clients
PUB["Public Internet User"] -->|"HTTPS"| PNGX["Public Nginx (*.example.com)"]
PNGX --> PBLOG["Public Service (e.g., blog/static)"]
%% VPN access
DEV["Your Device\n(WireGuard Client)"] -->|"VPN Tunnel"| WG["WireGuard Server (10.8.0.0/24)"]
%% Internal name + reverse proxy (VPN-only)
WG -->|"DNS"| DNS["Internal DNS (172.24.0.4)"]
WG -->|"HTTPS"| INGX["Internal Nginx (172.24.0.2)"]
%% Private services
subgraph DOCKER["Docker Private Networks"]
INGX --> VAULT["Vaultwarden"]
INGX --> NOTES["Notes / Joplin"]
INGX --> GIT["Git Service"]
end
Then I added a mandatory internal DNS service. All traffic coming in through the VPN can only use this DNS for name resolution. There are many mature options for this in practice, like AdGuard Home, which can also take care of ad blocking and DNS hijacking at the same time. Besides resolving the normal network traffic that passes through, this DNS service also specifically handles all DNS resolution under *.vpn.example.com, for example:
git.vpn.example.comnotes.vpn.example.comvault.vpn.example.com
All of these resolve to the IP the internal Nginx listens on, 172.24.0.2. So when the VPN is connected, I can just type the domain name into the browser and get straight to the internal service. All the traffic stays inside the internal network. It’s best if this domain is registered under your own name. Then, in your external DNS settings, set *.vpn.example.com to NXDOMAIN or your VPS’s IP address. That way, if you accidentally try to reach an internal service without going through the VPN, the traffic won’t get forwarded somewhere else by mistake.
Isolating Database Containers
A database shouldn’t be on the same Docker network as unrelated services. So I did one more thing: each service and its database get their own isolated bridge. On this bridge, only these two containers can talk to each other, and the bridge isn’t connected to any external network. In other words, even if a service gets compromised, the only thing it can reach is its own database, not every database on the server. Like this:
services:
db:
image: postgres:16-alpine
...
networks:
- iso
restart: unless-stopped
joplin:
image: git.stdv.de/saturneric/joplin:latest
...
depends_on:
- db
networks:
- iso
- vpn
restart: unless-stopped
networks:
iso:
internal: true
vpn:
external: true
You can see that db only talks one-to-one with joplin on the iso network, and this network blocks direct access from inside it to the outside network (internal: true). So if another service gets compromised, it generally can’t reach my joplin database over the network. But this isn’t “absolutely secure.” It always assumes the attacker hasn’t got access to the host. Still, in the real world, reducing the chance of lateral movement is a really important layer of protection in itself.
This actually also helps avoid hostname / database name conflicts. When a lot of databases on the same network use the same hostname, some services may end up connecting to the wrong database now and then.
Firewall Strategy
If you’re using a VPS, my suggestion is to use the firewall from your cloud provider first, and keep host firewall rules to a minimum. For the external firewall, limit the inbound ports you allow as strictly as you can, and reach your services through domain names and the reverse proxy. There are a few reasons. Two layers of firewall get confusing very easily, and it’s easy to forget which one you configured and which one you didn’t. I also found that Docker port mapping sometimes bypasses the local firewall, which can expose internal service ports by accident, and a lot of the time I didn’t even notice. And the cloud firewall can block large-scale scanning traffic early, which moves that compute cost onto the cloud provider.
Usually the cloud firewall only allows these inbound ports:
- 80 / 443
- The VPN port
- SSH
- Other ports you think really need to be open
Even if other ports are listening on the host, they’re invisible from the outside as long as the cloud firewall doesn’t allow them. You can only reach them through the VPN, which saves a lot of worry.
SSH Security
There are lots of other great articles on this topic, so I’ll just cover some very basic but really important points. These are also things I still do all the time:
- Disable SSH login for root. If you need root, use a normal user plus sudo.
- Don’t make the normal user’s SSH username too easy to guess, like admin.
- Give the normal user a long random password (I suggest generating it with a password manager), and use key-based login by default day to day.
- Optional: only allow key-based login for the normal user and disable passwords. (Be careful about the case where the key isn’t backed up and then you lose the device.)
A lot of people suggest changing the SSH port. On whether to change it in a personal environment, here’s my own view:
- In a personal environment, the security benefit is limited
- Some configuration later on gets more complicated
- In the end it depends on your own habits
Afterword
Actually, I’ve now moved to a dedicated server instead of a VPS, which is like renting a physical server in a data center that you can actually see. That’s because I now need to host dozens of containers (I went through them all, and I need every one of them). I think this shows that self-hosting really has become technical infrastructure I can’t do without day to day. It also shows that I think spending more money on it every month is really worth it.
Also, I should point out that in some places, the setup in this post, where one private VPN carries both your internal service traffic and your normal browsing traffic, is hard to pull off. For example, the server’s uplink bandwidth may be very expensive there, or the traffic may be metered. In that case, my suggestion is to do split routing ahead of time on the software router at home: separate out the self-hosting traffic first, and let normal browsing traffic go out through your home connection.
One more thing. Even if your server has enough uplink bandwidth to support a private VPN, a lot of the time you probably don’t want to browse the web with your VPS’s IP, because that directly exposes your identity. A better option is to send the traffic on to a VPN server from another VPN provider, and then go out through the exit IP it provides. I have a mature solution for this that I’ve been using myself for a long time. You can check out my blog post: Building a Personal Chained VPN Network: Efficient Privacy Protection, Unlimited Device Management, and Remote Access.