Drogon 服务的简要配置
带注释
server.json:
{
"listeners": [{
// IP
"address": "0.0.0.0",
// 端口
"port": 10003,
// 是否使用https
"https": false
}],
"app": {
// 线程数量
"number_of_threads": 16,
// 允许使用session
"enable_session": false,
"session_timeout": 0,
// 静态资源请求根目录 图片之类的可以直接放在这个目录下 请求
"document_root": "./",
// 主页
"home_page": "index.html",
"use_implicit_page": true,
"relaunch_on_error": true,
"upload_path": "uploads",
"max_connections": 100000,
"max_connections_per_ip": 0
},
// 插件
"plugins": [{
// 记录访问日志的插件, Drogon自带的
"name": "drogon::plugin::AccessLogger",
// 插件依赖项
"dependencies": [],
// 插件配置
"config": {
// 访问日志的存放目录, 这个目录不存在的话要手动创建
"log_path": "./log/access",
"log_format": "",
// 文件名称
"log_file": "access.log",
"log_size_limit": 0,
"use_local_time": true,
"log_index": 0
}
}]
}
无注释
server.json
{
"listeners": [{
"address": "0.0.0.0",
"port": 10003,
"https": false
}],
"app": {
"number_of_threads": 16,
"enable_session": false,
"session_timeout": 0,
"document_root": "./",
"home_page": "index.html",
"use_implicit_page": true,
"relaunch_on_error": true,
"upload_path": "uploads",
"max_connections": 100000,
"max_connections_per_ip": 0
},
"plugins": [{
"name": "drogon::plugin::AccessLogger",
"dependencies": [],
"config": {
"log_path": "./log/access",
"log_format": "",
"log_file": "access.log",
"log_size_limit": 0,
"use_local_time": true,
"log_index": 0
}
}]
}
访问日志内容示例
20221008 15:00:08.926000 GET /api/url1/url1/url1?x0=105.70958541299262&y0=43.16490110260108&x1=127.1293811822103&y1=35.4620463158539¶m1=1 [0] (192.168.0.155:10271 - 192.168.0.80:10003) 200 OK 53588 1.923
drogon中使用此配置文件
drogon::app().loadConfigFile("./server.json");
drogon::app().run();