当前位置: 首页 > 文档资料 > HI-NGINX 帮助文档 >

C++ 示例

优质
小牛编辑
114浏览
2023-12-01
#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/usr/local/nginx/include -shared -fPIC hello.cpp -o hello.so

install hello.so /usr/local/nginx/cpp

location ~ \.do {
  rewrite ^/(.*)\.do$ /$1 break;
  hi cpp/hello.so;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群