What is it?
For a couple of year I got some virtual servers for my own company. On one of those I run Debian 8 (hosted via kvm) with DirectAdmin.
In this article I’ll write how I managed to get a sample .NET Core WebAPI running on this environment.
Update 2017-03-27: Used Apache as proxy
Steps to get there
First I start by installing .NET Core on my environment.
[code]apt-get install curl libunwind8 gettext
curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?linkid=843453
mkdir -p /opt/dotnet && tar zxf dotnet.tar.gz -C /opt/dotnet
ln -s /opt/dotnet/dotnet /usr/local/bin[/code]
Next, I protected my working directory, as this is already visit-able from my current webpage, via a .htaccess file.
DirectAdmin also handles SSH access for users, in the control panel it is as simple as chaning a checkbox.
For this project I’m going to try Visual Studio Team Services, instead of GitHub.
In order to get this repository on my webserver, I used the following commands. I’ve already setup the token access for my user before.
[code]git init .
git remote add -t \* -f origin https://user:[email protected]_git/repository
git checkout master
git pull[/code]
Having a token makes it easy to revoke access if needed, and saves me the trouble of typing in the password every pull that I make.
The idea is to create a script that does the next steps:
- Pulls the latest git code;
- Runs dotnet build;
- Runs dotnet folder/output.dll &.
That turned out to not be the problem, the problem is more that I didn’t want to open port 5000 (in my case), and port 80 was already taken by Apache on the server. Having nginx would be overkill for my purpose, so I found a solution that covers my needs:
- Run the .NET Core Kestrel webserver that only listens to localhost port 5000;
- Use a proxy PHP script that interacts between the outside world and the webapi.
As my website already has https support (via the friends of Let’s Encrypt), I don’t have to worry to much about that part handling in Kestrel. Also, remember that I setup an .htaccess file in oder to disallow any other IP than my trusted ones to access this environment.
TODO
- Create a start/stop functionalaty, right now this is all done via the command line;
- Create pull latest git and build automatically, again, this is now done via the command line;
- Check the performance implications that this proxy might cause.
Update 2017-03-27: Used Apache as proxy
With DirectAdmin it is possible to set a custom HTTPD per domain. I created a new domain for this project (actually a subdomain but added it as a domain in DirectAdmin).
Then I can set the specific HTTPD configuration in order to create a proxy:
[code]ProxyRequests Off
ProxyPreserveHost Off
<Proxy *>
Order deny,allow
Deny from all
Allow from 1.2.3.4
</Proxy>
ProxyPass / http://localhost:5000/
ProxyPassReverse / http://localhost:5000/[/code]
31 thoughts on “Run .NET Core on Debian 8 with DirectAdmin”
Comments are closed.