BCHS is a software stack for web development. It uses a BSD based OS (operating system) as the server's system, in my opinion the best suited OS for servers is OpenBSD because it is designed with code correctness and proactive security in mind, it has it's own software ecosystem made to work best together, software we will be using is httpd, LibreSSL and clang. httpd is OpenBSD's own http server, it is much more minimal than something like nginx or apache, it has everything we need and it's already there. C is the simplest programming language, it's basically just a portable assembly with a set of development tools and libraries. We won't be using SQLite as we're just making a simple static website.
Network
- Open ports 80 and 443 on your router.
- Enable incoming connections on ports 80 and 443 in your system (OpenBSD) firewall. It's allowed by default.
OpenBSD
doas rcctl enable httpdStart the server on startup automatically.doas rcctl enable slowcgiStart the slowcgi on startup automatically.doas rcctl start httpdStart server for now without the need to reboot.doas rcctl start slowcgiStart slowcgi for now without the need to reboot.doas vi /etc/httpd.confEdit httpd config file.
server "http" {
listen on * port 80 block return 301 "https://$HTTP_HOST$REQUEST_URI"
}
server "https" {
listen on * tls port 443
tls {
certificate "/etc/ssl/lubiak.k.vu.crt"
key "/etc/ssl/private/lubiak.k.vu.key"
}
fastcgi
root "/cgi-bin/cgi"
}C
vi ~/cgi/cgi.cEdit the source code of your website.
#include <err.h> /* err(3) */
#include <stdlib.h> /* EXIT_xxxx */
#include <stdio.h> /* puts(3) */
#include <unistd.h> /* pledge(2) */
int main(void)
{
if (pledge("stdio", NULL) == -1)
err(EXIT_FAILURE, "pledge");
puts("Status: 200 OK\r");
puts("Content-Type: text/html\r");
puts("\r");
puts("<!DOCTYPE html>\n");
puts("<html lang='en'>\n");
puts("<head>\n");
puts("<title>BASED WEBSITE</title>\n");
puts("<meta charset='UTF-8'>\n");
puts("<meta name='viewport' content='width=device-width, initial-scale=1'>\n");
puts("</head>\n");
puts("<body>\n");
puts("<h1>Hello, world!</h1>\n");
puts("</body>\n");
puts("</html>\n");
return EXIT_SUCCESS;
}vi ~/cgi/cgi.shAutomate the compilation and deployment of your source code.
#!/bin/sh
cc -static -g -W -Wall -Wextra -o cgi cgi.c
doas install -o www -g www -m 0500 cgi /var/www/cgi-binTLS
openssl ecparam -name secp384r1 -genkey -noout -out /etc/ssl/private/lubiak.k.vu.keyGenerate a NIST/SECG curve over a 384-bit prime field ECDSA key.openssl req -key /etc/ssl/private/lubiak.k.vu.key -new -out /etc/ssl/private/lubiak.k.vu.csrGenerate Certificate Signing Request, if you want to have a certificate signed by a Certificate Authority then give them/etc/ssl/private/lubiak.k.vu.csrand place the received certificate in/etc/ssl/lubiak.k.vu.crt, if you want to sign your certificate yourself (like I did) then go to the next step.openssl x509 -sha256 -req -days 365 -in /etc/ssl/private/lubiak.k.vu.csr -signkey /etc/ssl/private/lubiak.k.vu.key -out /etc/ssl/lubiak.k.vu.crtGenerate a self-signed certificate that expires after 365 days.
Final deploying
sh ~/cgi/cgi.shCompile and deploy your source code.doas rcctl restart httpdRestart the httpd server to apply your configuration.