百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
B

BlogTech

> 编程语言
开源

为我的博客定制的 Web 服务器

347 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

为我的博客定制的 Web 服务器

BlogTech

BlogTech is a toolkit for managing small to medium websites. It supports HTTPS, virtual hosts, automatic certificate management (via ACME) and a client for remote management of the server.

⚠️ Note that BlogTech is still in the testing phase. Having said that, I have been serving https://coz.is/ successfully for a couple weeks using version 0.4.x

(If you are coming for the old, single-file version of BlogTech refer to the single_file branch.)

Here are some discussions about BlogTech on the internet:

  • Hacker News
  • r/C_Programming
  • r/hacking

Table of Contents

  • Quick Start
  • Authentication
  • Virtual Hosts
  • Enabling HTTPS
  • Enabling ACME
  • Testing the ACME Client
  • Configuration Files
  • Crash Logger
  • Setting up BlogTech as a Daemon

Quick Start

BlogTech runs on Linux and Windows (with limitations, see the HTTPS section). To compile it on Linux, you need to install the OpenSSL development library:

bash
# Ubuntu/Debian
sudo apt install libssl-dev gcc

To compile on Windows, you need to install clang.

Once you're done installing, you can build BlogTech by running

bash
# Linux
./build.sh

# Windows
.\build.bat

This will create the blogtech (Linux) or blogtech.exe (Windows) executable.

You can install it on Linux by calling the install script:

bash
# Linux
./install.sh

You can start a BlogTech server by running:

bash
mkdir docroot

# Linux
./blogtech --serve --document-root=docroot --skip-auth-check

# Windows
.\blogtech.exe --serve --document-root=docroot --skip-auth-check

This will start an HTTP server listening on 127.0.0.1:8080 and serving content from the docroot directory (which, is still empty).

You can view the website by opening a web browser and visiting http://127.0.0.1:8080/. Of course you will get a code 404 since there is nothing there yet!

So let's upload a file! Open a second terminal (to keep the server running) and create an HTML file by running the following:

bash
# Linux
echo "Hello, world" > index.html

# Windows
"Hello, world" | Out-File index.html

Now you can use BlogTech in "client mode" to upload the file

bash
# Linux
./blogtech --put --remote=http://127.0.0.1:8080 index.html

# Windows
.\blogtech.exe --put --remote=http://127.0.0.1:8080 index.html

You should now find the text "Hello, world" when visiting http://127.0.0.1:8080/!

Even though we ran client and server on the same machine, this would have worked the same if the server was running on a remote machine.

You can also download or delete remote files using the --get and --delete options!

Authentication

Authentication Options

Requests that would modify resources on the server are digitally signed using an HMAC/SHA256 signature. For this to work, client and server must share the same secret key, which is by convention stored in a admin.pwd file.

The password is specified using the --auth-password-file option:

bash
./blogtech --serve --auth-password-file=admin.pwd --document-root=docroot
./blogtech   --put --auth-password-file=admin.pwd --remote=http://127.0.0.1:8080 index.html

# (Use .\blogtech.exe if you are Windows)

Without a password file, all requests that would require authentication will be rejected. Also, empty passwords will be rejected.

During development, it's useful to allow all requests to be automatically be regarded as authenticated. You can do so with the --skip-auth-check, in which case the --auth-password-file option will be ignored if present. Of course you should use this with caution!

Authentication Headers

An authenticated HTTP request looks like this:

PUT /index.html HTTP/1.1\r\n
Host: 127.0.0.1:8080\r\n
Connection: Close\r\n
Content-Length: 22\r\n
X-BlogTech-Nonce: 80I5x5gfNC6yVTigxGf8xMDt+iVg3Nl6gjBi9Z4gaqE=\r\n
X-BlogTech-Timestamp: 1765730409\r\n
X-BlogTech-Expire: 300\r\n
X-BlogTech-Signature: S1jP/V6lTXqdjr2Mfk0N2C+0bCNsOxscifrUtRgJCw0=\r\n
\r\n
I'm a signed request!\n

The X-BlogTech- headers ensure that the request was not forged or used in a replay attack. More specifically:

  • X-BlogTech-Nonce contains a token chosen at random by the client
  • X-BlogTech-Timestamp contains the UNIX timestamp of when the request was first signed
  • X-BlogTech-Expire contains the number of seconds the request is valid from the time it is signed
  • X-BlogTech-Signature contains the Base64-encoded HMAC of the request information.

The signature is obtained by calculating the canonical version of the request string:

\n
\n
\n
\n
\n
\n
\n
\n

And calculating its HMAC/SHA256 using the authentication password as key. The result is then Base64-encoded (with padding).

Note that the nonces previously seen by the server are stored in-memory. This means that if the server reloads it will forget all previously seen nonces. This allows requests that are not expired to be replayed.

Virtual Hosts

BlogTech allows you to host multiple websites on the same server. For this to work you just need to specify the domain names using the --domain option:

bash
./blogtech --serve --document-root=docroot --domain=websiteA.com --domain=websiteB.com

BlogTech will then generate a directory per domain inside the document root

docroot
  default
  websiteA.com
  websiteB.com

Requests directed to a host will refer to the directory associated to that host. If a request isn't associated to a specific folder, it refers to the default one.

For instance, the following commands

./blogtech --put --remote=http://websiteA.com file1.html
./blogtech --put --remote=http://websiteB.com file2.html
./blogtech --put --remote=http://other.com file3.html

Will store the files as:

docroot/websiteA/file1.html
docroot/websiteB/file2.html
docroot/default/file3.html

Enabling HTTPS

HTTPS is only supported on Linux as the underlying HTTP library cHTTP implements HTTPS using OpenSSL. If you are on Windows, only HTTP is available for both client and servers.

To enable HTTPS, you need use the --https-enabled flag and load the certificate and private key using the --cert-file and --cert-key-file options.

bash
./blogtech --serve --https-enabled --cert-file=cert.pem --cert-key-file=key.pem

By default, the server will listen on 127.0.0.1:8443, but you can change this using the --https-addr= and --https-port= flags.

If you're not familiar with this process, the certificate is usually issued by a Certificate Authority (such as Let's Encrypt) after demonstrating the you own a domain. During development, it's useful to use a self-signed certificate, which can be generated with the following commands:

bash
openssl genpkey -algorithm RSA -out key.pem -pkeyopt rsa_keygen_bits:2048
openssl req -new -x509 -key key.pem -out cert.pem -days 365

Note that browser won't allow you to navigate to HTTPS servers that use self-signed certificates, while cURL only allows you to do so with the --insecure flag.

If you happen to need more than one certificate, you can pass additional certificates using the --extra-cert option:

bash
./blogtech --serve --https-enabled --cert-file=cert1.pem --cert-key-file=key1.pem --extra-cert=domain2.com,cert2.pem,key2.pem --extra-cert=domain3.com,cert3.pem,key3.pem

The certificate provided using the --cert-file and --cert-key options is served to clients by default, while the extra certificates are used when clients ask for specific domains (domain2.com and domain3.com in the example).

(Note: the command is quite long, but you can move command-line options to a configuration file)

Enabling ACME

The ACME protocol allows web servers to automatically request certificate authorities to issue a certificate. You can basically start the server in HTTPS mode without a certificate, and a couple seconds later.. there is the certificate!! It's pretty magic if you ask me.

If you're running this in production, be sure to:

  • Run the HTTP server on port 80
  • Create a DNS record that associated the domain the machine running the server If you want to run the ACME client locally, refer to the Testing the ACME client section to run an ACME server locally.

Enable ACME using the --acme-enabled flag alongside the HTTPS flags. Unlike regular HTTPS mode, the server expects the certificate not to exist. You also need to provide some values required to compile the certificate, such as the domain to certify, email, country code, organization name, and that you agree to the CA's terms of service:

bash
./blogtech --serve --https-enabled --cert-file=cert.pem --cert-key-file=key.pem --acme-enabled --acme-domain=example.com [email protected] --acme-country=IT --acme-organization=me --acme-agree-tos

(Note: the command is quite long, but you can move command-line options to a configuration file)

If all goes well, you should find that the following files are generated:

  • acme_key.pem: The secret key associated to the ACME account
  • cert.pem (or whatever you pass to --cert-file): The issued certificate
  • key.pem (or whatever you pass to --cert-key-file): The private key associated to the certificate

If anything goes wrong, error messages are logged to the acme.log file.

Note that you can let ACME handle multiple domains by simply passing multiple --acme-domain options. The resulting certificate will include all domains.

Testing the ACME client

To test the ACME client on Linux you will need to install Docker and clone the Pebble ACME server.

Modify the docker-compose.yml file to add the following lines:

dockerfile
version: "3"
services:
  pebble:
    image: ghcr.io/letsencrypt/pebble:latest
    command: -config test/config/pebble-config.json -strict
    ports:
      - 14000:14000 # HTTPS ACME API
      - 15000:15000 # HTTPS Management API
    networks:
      acmenet:
        ipv4_address: 10.30.50.2
    extra_hosts:
      - "local-test-websiteA.com:host-gateway"  `.

## Configuration Files

BlogTech allows you to move any number of command-line arguments to a configuration file.

Say you have the following very verbose command:

```sh
./blogtech --serve --https-enabled --cert-file=cert.pem --cert-key-file=key.pem --acme-enabled --acme-domain=example.com [email protected] --acme-country=IT --acme-organization=me --acme-agree-tos

You can run the same command by creating the following blogtech_server.conf file

https-enabled     yes
cert-file         cert.pem
cert-key-file     key.pem
acme-enabled      yes
acme-domain       example.com
acme-email        [email protected]
acme-country      IT
acme-organization me
acme-agree-tos    yes

and running BlogTech as:

bash
./blogtech --serve --config=blogtech_server.conf

BlogTech will automatically load a configuration file if named exactly blogtech.conf, which means you can do simply:

bash
./blogtech --serve

If you want to ignore the implicit config file, use the --no-config flag:

bash
./blogtech --serve --no-config

…


[Unit]
Description=The BlogTech web server

[Service]
Type=simple
ExecStart=/root/blogtech/blogtech -s
Restart=on-failure
WorkingDirectory=/root/blogtech/

[Install]
WantedBy=multi-user.target

This will make sure blogtech is spawned at startup and will restart it when it crashes. Any server options will be automatically be loaded by a /root/blogtech/blogtech.conf file.

Copy the service file to `/etc/systemd/s

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言