Bare-bones Web Server


Need a bare-bones web server to do some testing? Look no further than Mojolicious!

In the previous post Bare-bones Root CA we looked into generating a certificate just a bit further the self-signed one: create a Certification Authority and have it generate the certificate from a certificate request.

How to test these certificates quickly? Mojolicious can help us quite quickly. First, let’s install it and ensure that we have also support for SSL, using this cpanfile:

requires 'Mojolicious';
requires 'IO::Socket::SSL';

Take a look to Installing Perl Modules if you don’t know what to do with the cpanfile above. My preferred way to do that is with Carton:


which creates a sub-directory local with modules in local/lib/perl5.

At this point, the following program will do:

#!/usr/bin/env perl
use Mojolicious::Lite;
get '/' => sub { $_[0]->render(text => "Hello, World!\n") };

Local version here.

I know, I know… no strict, no warnings!!! Well, it’s so short and so… void of code that it’s really not needed.

To start it, there are a few options. The most straightforward is the following:

perl -I local/lib/perl5 daemon \
   -l 'https://*:3000?cert=./server.crt&key=./server.key'

At this point we’re ready to start experimenting… or are we? Let’s see:

$ curl https://localhost:3000/
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here:

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.

Well… of course we have to instruct the client to trust the root CA certificate, but we’re not there yet:

$ curl --cacert ca.crt https://localhost:3000/
curl: (51) SSL: certificate subject name '' does not match target host name 'localhost'

Our example certificate here is for, but we’re sending our query to localhost (i.e. a different name). We can do two things:

  • re-generate the certificate for the server, putting localhost instead of, OR
  • fiddle with /etc/hosts to add an entry for, like this:
$ cat /etc/hosts	localhost
# ...

Now we’re finally ready:

curl --cacert ca.crt
Hello, World!


Comments? Octodon, , GitHub, Reddit, or drop me a line!