lwhttpd:main
lwhttpd
简述
lwhttpd(全称lightweight httpd)是一个轻量级和高性能的web服务器. 支持CGI, FastCGI(计划中), proxy (计划中)和静态资源访问
本项目主页lwhttpd.org
特点
- 支持GET和POST
- 支持静态资源和CGI
- 使用了EPOLL
- 支持IPv4和IPv6
- 使用CMake构建,仅支持Linux
- 使用了线程池
- 包含一个CGI示例程序
- 支持通过JSON配置
警告
TLS还未支持,也就是说还不能使用HTTPS
开始
准备
为了编译和运行本程序,你需要一下条件:
- 一台Linux计算机(受限于CGI)
- 支持C++17的C++编译器
- 支持pthread线程的编译器
- CMake 3.0及以上版本(我没试过更低版本)
- BOOST 1.75及以上版本
编译
# 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.浏览器
lwhttpd/main.txt · Last modified: by sandro
