Table of Contents

lwhttpd

简述

lwhttpd(全称lightweight httpd)是一个轻量级和高性能的web服务器. 支持CGI, FastCGI(计划中), proxy (计划中)和静态资源访问
本项目主页lwhttpd.org

特点

警告

TLS还未支持,也就是说还不能使用HTTPS

开始

准备

为了编译和运行本程序,你需要一下条件:

编译

# Debug version
$ cmake -S . -B ./build -DCMAKE_BUILD_TYPE=Debug
# Release version(default)
$ cmake -S . -B ./build
$ cd build/
$ make -j8

配置

已支持通过JSON配置

{
  "server_name": "www.mydomain.com",
  "listen": [
	{
	  "address": "0.0.0.0",
	  "port": 80
	},
	{
	  "address": "::",
	  "port": 80
	}
  ],
  "web_root": "/var/htdocs",
  "work_thread": 0,
  "tls": {
	"cert_file": "/cert/tls.cert",
	"key_file": "/cert/tls.key"
  }
}

运行

# Make the 'htdocs' directory, and copy demo.cgi to the directory
$ tree
|-- htdocs
|   |-- demo.cgi
|   `-- index.html
`-- lwhttpd
$ sudo ./lwhttpd

测试

1.CURL

# IPv4
$ curl -v http://127.0.0.1
$ curl -v http://127.0.0.1/demo.cgi?hello
# IPv6
$ curl -v http://[::1]
$ curl -v http://[::1]/demo.cgi?hello
# auto
$ curl -v http://localhost/demo.cgi?hello

2.浏览器

浏览器直接访问http://localhost/demo.cgi?hello