Paozhu logo Paozhu Docs
教程目录
OPS

服务器配置

conf/server.conf 的全局段、端口、目录、HTTP/2 与运行开关。

一份最小可用配置

conf/server.confini
[default]
httpport            = 80,8080
httpsport           = 443
ip6_listen_enable   = 1
http2_enable        = 1
global_http2_enable = 1
deamon_enable       = 0
mainhost            = www.example.com
certificate_chain_file = www.example.com.pem
private_key_file       = www.example.com.key
tmp_dh_file            = dh4096.pem
chain_crt_file         = www.example.com.crt

wwwpath             = ./www/default
index               = index.html
directorylist       = 1
usehtmlcache        = 1
usehtmlcachetime    = 3600

session_type        = 1
rate_limit_status   = 0
acme_auto           = 0
ocsp_intv_time      = 14400

关键配置项

键默认说明
httpport80支持逗号分隔多个端口
httpsport443同上
http2_enable1HTTP/2 + ALPN 开关
global_http2_enable未设置决定虚拟站点是否继承开启 HTTP/2
cothreadnum6协程运行线程数
ioc_thread_num8ORM / HTTP io_context 上限
orm_thread_pool_num4ORM 线程池;0 用 CPU 核数
wwwpath./www/default静态站点根目录
indexindex.html默认首页
session_type10 文件 / 1 内存 / 2 Redis / 3 Memcache
rate_limit_status0总限流开关
usehtmlcache1静态文件缓存开关;TTL 下限 10 秒
deamon_enable0后台守护模式
ocsp_intv_time14400OCSP 刷新节拍数,运行时乘 5 秒

端口与静态目录

httpport 与 httpsport 由代码按逗号循环解析,空值时分别回落到 80 / 443。静态文件根目录由 wwwpath 决定,index 决定默认首页;directorylist = 1 时会显示目录列表。

terminalbash
lsof -i :80
sudo ss -tlnp | grep 80
# change conf/server.conf when the port is busy:
# httpport = 8080

HTTP/2 的继承规则

默认站点的 http2_enable 控制自己;虚拟站点创建时继承的是 isallnothttp2,而该值随后会被 global_http2_enable 无条件覆盖。当前默认配置只写了 http2_enable = 1,所以未在站点段显式开启的虚拟站点默认是关闭 HTTP/2 的。

未使用的配置键

以下键仍出现在配置文件中,但当前 C++ 代码没有读取点:threadmax、threadmin、bmcport、staticfile_cache_num、modelspath、viewpath、controlpath、libspath、pluginspath。保留它们无害,但调它们不会生效。

启动与停止

terminalbash
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j8
cd ..
lsof -i :80
./bin/paozhu conf/server.conf
curl -I http://127.0.0.1/
tail -f log/*