0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

nginx環境でC++モジュールのCGIを動かすためのメモ

Posted at

必要なパッケージ

apacheでは拡張子.cgiのハンドラーを登録すれば何となく動く。
nginxの場合はFastCGIを経由させてcgiモジュールを動かす。
動かすために必要なパッケージは以下の通り。
nginx
fcgi (要epel-release)
fcgi-devel (要epel-release)
fcgiwrap (要epel-release)
spawn-fcgi (要epel-release)

上記パッケージをyumかdnfで導入する。

spawn-fcgiの設定

# vi /etc/sysconfig/spawn-fcgi

以下の行を追加する

# Example :
#SOCKET=/var/run/php-fcgi.sock
#OPTIONS="-u apache -g apache -s $SOCKET -S -M 0600 -C 32 -F 1 -P /var/run/spawn-fcgi.pid -- /usr/bin/php-cgi"
OPTIONS="-u nginx -g nginx -a 127.0.0.1 -p 9001 -P /var/run/spawn-fcgi.pid -- /usr/sbin/fcgiwrap"

nginxの設定

cgiを動かしたいドメインのディレクティブ内で.cgiの処理を定義する

ngin.conf

    location ~ \.cgi$ {
        fastcgi_pass   127.0.0.1:9001;
        fastcgi_index  index.cgi;
        fastcgi_param  SCRIPT_FILENAME  /$document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

C++でCGIを実装するのに便利なC/C++ライブラリ

Cgicc

gnuが提供しているライブラリ。
cgicc
実行モジュールから簡単にcgiのPOST/GETのデータをパースしてくれる。
カスタムヘッダーなどはstd::getenvで取得。

...
        const char *tmp = std::getenv("HTTP_CONTENT_TYPE");
        std::string content_type(tmp ? tmp : "");
        if (!content_type.empty()) {
            std::cout << "HTTP_CONTENT_TYPE:" << content_type << std::endl;
        }
...

nlohmann/json

nlohmann/json
jsonデータのパース・生成

MySQL Connector/C++

Mysqlで接続する場合に必要。
8.0からレガシーなアクセス方法であるJDBCのほかに
X Dev APIなるプロトコルでもアクセス可能。
但しmysql限定でmariadbでは使えないっぽい?

cpplinq - LINQ-like list manipulations for C++11

c++でC#のLinqっぽい操作ができるライブラリ。

SQLクエリビルダー

上記以外にSQLのクエリを安全に生成してくれるライブラリがあればいいんだけど
これといったものがない。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?