For this project, I needed a small webserver to host a single web page. After some research, I chose to install Lighttpd webserver on Ubuntu. As of yet, I don’t have an opinion of what webserver is better or worse for a single web page. I searched throughout the web to find guides on everything I needed to get the webserver running. I will include the links to helpful articles I found throughout this post. Check out my previous post here if you want to see how first I deployed my Ubuntu server. Initial step is to install Lighttpd.

Install Lighttpd

You can find the latest copy of Lighttpd here. For reference, I followed this guide here. Update your instance of Ubuntu.

sudo apt-get update -y

As of this post, Lighttpd is a part of the default repo, so just run this command.

sudo apt-get install lighttpd -y

You can check on the status of the service by running this command.

systemctl status lighttpd

The main configuration file is located here, I used nano to edit the files.

sudo nano /etc/lighttpd/lighttpd.conf

From here you can change the directory of the document root if needed, add modules for different features, and enable ssl certificates.

Here is an example of the modules that I have enabled. If you want to research what modules you need refer to the link above for Lighttpd or open the ‘man’ page.

server.modules = (
        "mod_indexfile",
        "mod_access",
        "mod_alias",
        "mod_redirect",
        "mod_openssl",
        "mod_redirect",
)

Next step I took was to think about HTTPS. This is required for my site if I want it to be accepted by modern browsers and be secure. Even though my site does not take any data from the user, HTTPS is free with LetEncrypt, so why not?

Enable HTTPS with Lighttpd

For reference, I started with this guide here for HTTPS. Use this command to install certbot on the server.

sudo apt-get install certbot

Next, use this command to create a certificate with Let’s Encrypt.

Note that after -w you should put the directory of your webserver, from the Lighttpd install above or wherever you have it installed. Also, after -d is the fully qualified domain name of your site.

sudo certbot certonly --webroot -w /var/www/http -d calc.powersjo.com

After you run through the prompts, combine both the private key and the certificate into one file. Use something like this command:

Note, be sure to change the FQDN of the website to your site.

cat /etc/letsencrypt/live/calc.powersjo.com/cert.pem /etc/letsencrypt/live/calc.powersjo.com/privkey.pem > /etc/letsencrypt/live/calc.powersjo.com/web.pem

Now it is time to go back to the configuration file of the Lighttpd server and edit it for HTTPS. The main configuration file is mentioned above. At the end of that file add something like this:

Note, change the ssl location to your website name and proper location. Also, the ‘#’ denotes a comment in the file. Lastly, be sure to change the document root and log location as appropriate to your site.

$SERVER["socket"] == ":443" {
ssl.engine = "enable"
ssl.pemfile = "/etc/letsencrypt/live/calc.powersjo.com/web.pem" # Combined Certificate
ssl.ca-file = "/etc/letsencrypt/live/calc.powersjo.com/chain.pem" # Root CA
server.name = "calc.powersjo.com" # Domain Name OR Virtual Host Name
server.document-root = "/var/www/html" # Document Root
accesslog.filename = "/var/log/lighttpd/calc.powersjo.com_access.log"
}

Finally, I opted to redirect all traffic from HTTP to HTTPS. You can accomplish this by adding this to the end of that file (I used the main Lighttpd docs page for reference):

$HTTP["scheme"] == "http" {
    url.redirect = ("" => "https://${url.authority}${url.path}${qsa}")
    url.redirect-code = 308
}

Move your website to Lighttpd

Now with your server ready to go, if you have not already, move your html and other files to your main website location on the server. I used WinSCP to transfer the files from my workstation to the Ubuntu server. Give the Lighttpd server a restart with this command and your page should be viewable over your network:

service lighttpd restart

The final product of my project was https://calc.powersjo.com.

More content will be posted from this project. Such as: the code and tools used to create it, how I setup the hosting with DDNS, auto renew of the SSL certificate and more.

Check out my previous blog post here.

Enter your address to subscribe to this blog and receive notifications of new posts!

People get crypto to read and post blogs. Publish0x is like Medium but the author and the reader get tips. Use my referral link below and check it out.

God bless you!

Published by Powersjo

If you want to contact me I can be found here: https://gab.com/Powersjo Christ is King