It's been a few years since I had a (shared) server up and running. However, it never felt particularly good, since I don't have much of an idea about configuration. Is it really secured well enough now? Are all ports closed? Do I need a firewall? How often do I actually make backups? And so on... The same old story.
And then, of course, there's more. How do I deploy my .NET services and make them available to the outside world? Do I need a reverse proxy? Which one should I use? And more important: How do I configure it properly?
Uberspace to the rescue
A dear friend of mine recently made me aware of the hoster Uberspace. I took a closer look at it and I am simply thrilled. You can just look at their website to see why Uberspace is awesome. This post is not meant for that.
What I want to show here is the process of deploying a new .NET service and making it publicly available using a subdomain. I'm just going to assume that you already have your ssh connection to the server up and running. If not, just have a look at the docs.
1. dotnet publish
This step is self-explanatory, but for the sake of completeness it should be mentioned anyway. So just run dotnet publish --self-contained=false -c release
.
2. scp
the service to the server
On the server you should create a directory for your app under ~/bin/
. In this example we just take ~/bin/my-app
. And there we throw the result of the dotnet publish
command via scp
in there.
3. register the service as a daemon
To run the service as a daemon, we simply create an .ini
file under ~/etc/services.d
. In our example, we call the file my-app.ini
, matching the bin
directory.
The content of the file looks like this:
[program:my-app]
directory=/home/my-user/bin/my-app
command=dotnet MyApp.dll
startsecs=60
Now we have to re-read and update the config. Just run supervisorctl reread
and supervisorctl update
one after the other.
4. create a subdomain
We want to make the service available over the net. So we just create a subdomain. This is very easy with Uberspace.
uberspace web domain add my-app.my-user.uber.space
That's all it takes. Uberspace automatically takes care of the Let's Encrypt certificates and everything else.
5. connect service and subdomain
Now there is only one small step left to connect the service to the subdomain. If you don't specify anything else, our .NET service runs as usual on port 5000, in which case you simply do the following:
uberspace web backend set my-app.my-user.uber.space --http --port 5000
Done. That's all. Just execute a few commands on the console and that's it. The service is now available using the desired subdomain.
Happy coding (and deploying)!