2 Star 1 Fork 0

Yanyi Wu / ngx_http_cppjieba_module

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

ngx_http_cppjieba_module

简介

CppJiebaNginx 扩展模块。 需要了解源码的可以参看 NginxModuleDevelopment

支持Docker

docker pull docker.cn/yanyiwu/nginx_cppjieba_server

用法

安装和配置

以下用法假设 ngx_http_cppjieba_module 下载后存放的地址是 /tmp/ngx_http_cppjieba_module (这个地址在 Nginx 编译时和词典加载时候会用到)

下载源码:

git clone git://github.com/aszxqw/ngx_http_cppjieba_module.git /tmp/ngx_http_cppjieba_module

进入 Nginx 源码目录:

./configure --add-module=/tmp/ngx_http_cppjieba_module/src

因为 ngx_http_cppjieba_moduleC++ 源码,所以作为 Nginx 模块编译的时候需要 修改 obj/Makefile

# 1. 在 "CC = gcc" 下面增加一行,如下
CXX = g++
# 2. 修改链接器为 g++ , 如下
LINK = $(CXX)
# 3. 修改 ngx_http_cppjieba_module.cpp 的编译器,从 $(CC) 改为 $(CXX) , 如下
$(CXX) -c $(CFLAGS)  $(ALL_INCS) \
    -o objs/addon/src/ngx_http_cppjieba_module.o \
    /tmp/ngx_http_cppjieba_module/src/ngx_http_cppjieba_module.cpp

这三步做完就可以 make && sudo make install nginx 了。

# 4. 修改 Nginx 配置文件 /usr/local/nginx/conf/nginx.conf
location /cppjieba {
    cppjieba /tmp/ngx_http_cppjieba_module/dict/jieba.dict.utf8 /tmp/ngx_http_cppjieba_module/dict/hmm_model.utf8 /tmp/ngx_http_cppjieba_module/dict/user.dict.utf8;
}

如果 ngx_http_cppjieba_module 的源码路径不是 /tmp/ngx_http_cppjieba_module, 将上述过程的 /tmp/xxx 改为 /your/path/xxx 即可。

启动 Nginx

/usr/local/nginx/sbin/nginx

测试

GET

curl "http://127.0.0.1/cppjieba?s=长春市长春药店"

POST

curl --data "长春市长春药店" "http://127.0.0.1/cppjieba"

预期结果:

["长春市", "长春", "药店"]

chrome 打开上述链接也可以,不过要 记得 设置浏览器的页面编码方式为 utf-8

客服

i@yanyiwu.com

The MIT License (MIT) Copyright (c) 2013 Yanyi Wu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

CppJieba 的 Nginx 扩展模块 展开 收起
C
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C
1
https://gitee.com/yanyiwu/ngx_http_cppjieba_module.git
git@gitee.com:yanyiwu/ngx_http_cppjieba_module.git
yanyiwu
ngx_http_cppjieba_module
ngx_http_cppjieba_module
master

搜索帮助