MicroHttpd is a HTTP (Web) Server written in .NET Core.
Demo Web Site: https://microhttpd.ml/
Currently, it supports:
- SSL, using a PFX file.
- Async IO.
- Dynamic and static content.
- Fixed length as well as variable length request/respond.
- Byte-range request for video streaming.
- Virtual hosts.
- Completely extensible.
Extend the code to do your own things that a normal web server wouldn't support, for example:
- Matching virtual host by cookies.
- HTTP over UDP.
- Optimizing performance for one specific use-case.
- Building your own MVC framework.
A Demo project is included, those are the steps to have a website up and running, with SSL:
- Start a new console application (.NET or .NET Core), then add a project reference to MicroHttp.Core.
- In your application's entry point Main(string[] args) method, create an instance of IHttpService:
using MicroHttpd.Core;
// Create the HTTP server,
// it doesn't do anything until you configure and start it.
var httpService = HttpServiceFacade.Create();
- Configuring virtual host, a.k.a document root, where the HTML/CSS/JS files are, as well as the ports and domain name.
// Configure virtual host - the domain name,
// the web root and ports.
httpService.AddVirtualHost(new VirtualHostConfig
{
// We'll set document root to the www directory of this project.
DocumentRoot = "/var/www/my-personal-website.com",
// Accept all host names,
// Other than MatchAll, you can also use
// MicroHttpd.Core.StringMatch.Regex, or,
// MicroHttpd.Core.StringMatch.ExactCaseSensitive
HostName = new MatchAll(),
// Accept incoming connections on port 8443,
// If you want to use port 443 and/or 80, add them here.
// (You'll need to start the application as root)
ListenOnPorts = new int[] { 8443 }
});
- Optionally, if you have a SSL certificate, you can configure the server to use it.
// Configure the server to use SSL,
// specifying path to the PFX file and its password.
httpService.AddSSL(
"/etc/my-personal-website.com.pfx"),
",g9e/~ArH=aH.k8C"
);
Notes: I got missing DLL exception when starting .NET Core with SSL on Ubuntu, fixed by installing libcurl3 package.
- That's it. Now you can start the server.
// Start the server
httpService.Start();
// Wait, this prevents the console program from exiting.
httpService.Wait();
More details on extending the code coming soon as a CodeProject tutorial, please watch this space.