跳转至

c++ 示例

#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;
}