忍者ブログ

ひつ(じのひよこが)プログラミングします。
お仕事や趣味で困ったこととか、何度も「あれ?どうだったかしら」と調べたりしたこととか、作ったものとか、こどものこととかを書きます
★前は週末定期更新でしたが今は不定期更新です

2024/05    04« 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  »06

Windows Subsystem for Linux 上で nginx 経由でアクセスするように ゆとシート2 for SW2.5 を動かす

前に Apache2 からアクセスするようにゆとシート2 for SW2.5 を動かしたので、nginx 経由でなんとかする。

いろいろあって nginx 経由で cgi したくなったので実験台に過去に動かした実績があるゆとシート2が選ばれたのである。前に紹介した時に比較してさらに強力な機能がゆとシート2 for SW2.5 には増えているので各位も触ってみてほしい。

手順パクった元

NginxでRubyのCGIを動かす - Qiita

この記事自身は FCGI Wrapの公式ページを参考にセットアップしました。 と言っているので FCGI Wrap | NGINX を読んだ方が良かったか、と今更後悔している。

バージョンとかとか

Ubuntu 16.04.6 を使っている。

nginx 1.10.3 を使っている。

fcgiwrap を入れる

sudo apt install fcgiwrap する。

設定ファイルをいじいじ

なんか、以下のような便利なやつがあるので流用する。

$ cat /usr/share/doc/fcgiwrap/examples/nginx.conf
# Include this file on your nginx.conf to support debian cgi-bin scripts using
# fcgiwrap
location ~ \.cgi$ {
  # Disable gzip (it makes scripts feel slower since they have to complete
  # before getting gzipped)
  gzip off;

  # Set the root to /usr/lib (inside this location this means that we are
  # giving access to the files under /usr/lib/cgi-bin)
  root  /usr/lib;

  # Fastcgi socket
  fastcgi_pass  unix:/var/run/fcgiwrap.socket;

  # Fastcgi parameters, include the standard ones
  include /etc/nginx/fastcgi_params;

  # Adjust non standard parameters (SCRIPT_FILENAME)
  fastcgi_param SCRIPT_FILENAME  /usr/lib$fastcgi_script_name;
}
$ cd /etc/nginx
# もともとあったファイルを退避
/etc/nginx$ sudo mv fastcgi.conf fastcgi.conf_bk
# 上述のファイルを複製
/etc/nginx$ sudo cp /usr/share/doc/fcgiwrap/examples/nginx.conf ./fastcgi.conf

適当なエディタで以下のようにいじる。太字部分がいじった部分。

/etc/nginx$ cat fastcgi.conf
# Include this file on your nginx.conf to support debian cgi-bin scripts using
# fcgiwrap

# なお、ここを /ytsheet とかにしてしまうと css とかが読めなくなる
# 拡張子が .cgi じゃないのであればまた設定は考えないといけない。
# TRPG 系なら .rb とか多いのでは?
location ~ \.cgi$ {
  # Disable gzip (it makes scripts feel slower since they have to complete
  # before getting gzipped)
  gzip off;

  # Set the root to /usr/lib (inside this location this means that we are
  # giving access to the files under /usr/lib/cgi-bin)
  # root        /usr/lib;

  # Fastcgi socket
  fastcgi_pass  unix:/var/run/fcgiwrap.socket;

  # Fastcgi parameters, include the standard ones
  include /etc/nginx/fastcgi_params;

  # Adjust non standard parameters (SCRIPT_FILENAME)
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

返す刃で nginx の config ファイルをいじる。太字部分がいじった部分。

server {
        include /etc/nginx/fastcgi.conf;

        # Apache2 で前に設定したときにここに入れたので
        root /var/www/html;

トラブルシューティング

403が返ってくる

また、ファイルのパーミッションが適切に設定されていないと 403 が返ってくる。リポジトリ記載のガイドとか、nginxで403を回避するために、パブリックファイルの権限についておさらい - Qiita とかを参考にしつついじる。

前回紹介したトラブルシューティング

Apache2 で動かしたときの情報記載のものは以下の感じ。詳細はリンク先を。

  • No such file or directory と言われる
    -> perl のインストールされているディレクトリがゆとシートの cgi ファイル指定の場所と違うのでは
  • 特定のモジュールがないというエラーが出る
    -> 必要なモジュールが入ってないと思われるので入れる
  • config.cgi が見つからないと言われる
    ->config.cgi.default ってファイルがあるはずなのでそれを config.cgi にリネームする

こんな感じで動いた。

PR

コメント

ただいまコメントを受けつけておりません。

ブログ内検索

P R