这里有新鲜出炉的精品教程,程序狗速度看过来!
hi-nginx 是一个基于 nginx 最新版开发的 c++ 应用服务器。它 100% 兼容 nginx。
使用 hi-nginx,开发者不必区分 nginx 的原有功能和 hi 的动态功能,两者是完全融合的。
安装方法:
--add-module=ngx_http_hi_module 就行。跟编译 nginx 原版无异。
使用方法:
- location / hello { hi hi / hello.so ;
- }
- hi_need_cache on|off;
- hi_cache_size 10;
- hi_cache_expires 300s;
- hi_need_headers on|off;
- hi_need_cookies on|off;
hello,world:
- #include "servlet.hpp"namespace hi {
- class hello : public servlet { public: void handler(request & req, response & res) { res.headers.find("Content-Type") - >second = "text/plain;charset=UTF-8"; res.content = "hello,world"; res.status = 200;
- }
- };
- }
- extern "C" hi: :servlet * create() {
- return new hi: :hello();
- }
- extern "C" void destroy(hi: :servlet * p) { delete p;
- }
- g++ -std=c++11 -I/home/centos7/nginx/include -shared -fPIC hello.cpp -o hello.so install hello.so /home/centos7/nginx/hi
或者使用 hi-project 脚本自动创建模板源文件和 Makefile
- hi-project a b cd a make make install
来源: http://www.phperz.com/article/17/0515/335069.html