!!!OpenBSD Webサーバ (httpd on OpenBSD 6.8) {{category OpenBSD,nolink}}OpenBSDのサーバ httpd の設定 (OpenBSD 6.8) 組み込まれている Web サーバが、Apache 1.3系 から(nginx になって)、OpenBSD 5.6 に独自のものに変更されている。 * 関連 man → [httpd(8)|https://man.openbsd.org/httpd.8], [httpd.conf(5)|https://man.openbsd.org/httpd.conf.5], [slowcgi(8)|https://man.openbsd.org/slowcgi.8] !!! webサーバ(httpd)の起動設定 !! 自動起動 '''/etc/rc.conf.local''' に設定を行う。 または、'''rcctl enable httpd''' で有効にする。それが /etc/rc.conf.local に反映される。 変数値は '''httpd_flags''' 。 # httpd web server httpd_flags= また、CGI を使う場合、slowcgi も起動させる。 変数値は '''slowcgi_flags''' 。 # FastCGI to CGI wrapper server slowcgi_flags= !!! webサーバ(httpd)の設定 '''/etc/httpd.conf''' に設定する。サンプルが /etc/examples/httpd.conf にある。 OpenBSD の httpd は、 '''/var/www''' に chroot されるようになっている。 !! 静的ドキュメント '''/var/www/htdocs''' 以下の静的ドキュメントを表示させる(/var/www に chroot されるので、ドキュメントルートは /htdocs)。 # $OpenBSD: httpd.conf,v 0.00 2021/01/01 00:00:00 xxxxx Exp $ server "default" { listen on * port 80 # Optional, but probably best - change your syslog.conf to do # what you want with it then. #log syslog root "/htdocs" directory auto index } # Include MIME types instead of the built-in ones types { include "/usr/share/misc/mime.types" # Necessary to ensure patch files show up as text not binary text/plain sig } !! 動的ドキュメント '''/var/www/cgi-bin''' 以下のプログラムを実行し結果を表示させる(/var/www に chroot されるので、パスは /cgi-bin)。 slowcgi を使用するので、合わせて起動する(起動するように設定しておく)。 また、slowcgi も /var/www に chroot されるので、sh や perl などのスクリプトを実行する場合は、/var/www 以下に必要なファイルを配置しておく必要がある。 # $OpenBSD: httpd.conf,v 0.00 2021/01/01 00:00:00 xxxxx Exp $ server "default" { # :中略 location "/cgi-bin/*" { fastcgi socket "/run/slowcgi.sock" directory no index root "/" #request strip 1 } } ! 動作確認1(プログラム) 下記の C言語プログラムを保存する #include #include #include int main(){ time_t now; puts("Content-Type: text/plain"); puts(""); puts("hello world"); now = time(NULL); puts(ctime(&now)); return (0); } ライブラリをスタティックリンクして、コンパイルする。 # clang -o test_cgi -static test_cgi.c chroot して実行できるか、確認する。 # chroot -u www /var/www/ /cgi-bin/test_cgi Content-Type: text/plain hello world Tue Nov 23 07:03:11 2021 # curl -sv http://localhost/cgi-bin/test_cgi * Trying 127.0.0.1:80... * Connected to localhost (127.0.0.1) port 80 (#0) > GET /cgi-bin/test_cgi HTTP/1.1 > Host: localhost > User-Agent: curl/7.72.0 > Accept: */* > * Mark bundle as not supporting multiuse < HTTP/1.1 200 OK < Connection: keep-alive < Content-Type: text/plain < Date: Tue, 23 Nov 2021 07:07:24 GMT < Server: OpenBSD httpd < Transfer-Encoding: chunked < hello world Tue Nov 23 07:07:24 2021 * Connection #0 to host localhost left intact ! 動作確認2(シェルスクリプト) #!/bin/sh echo "Content-Type: text/html\n\n"; echo "hello world"; echo "HOST is $HTTP_HOST"; シェルが動くようにコピーする。 # cp -p /bin/sh /var/www/bin/ # chroot -u www /var/www/ /cgi-bin/test_sh.cgi Content-Type: text/html hello world HOST is # curl -sv http://localhost/cgi-bin/test_sh.cgi * Trying 127.0.0.1:80... * Connected to localhost (127.0.0.1) port 80 (#0) > GET /cgi-bin/test_sh.cgi HTTP/1.1 > Host: localhost > User-Agent: curl/7.72.0 > Accept: */* > * Mark bundle as not supporting multiuse < HTTP/1.1 200 OK < Connection: keep-alive < Content-Type: text/html < Date: Tue, 23 Nov 2021 07:20:13 GMT < Server: OpenBSD httpd < Transfer-Encoding: chunked < hello world HOST is localhost * Connection #0 to host localhost left intact ! 動作確認3(perl スクリプト) #!/usr/bin/perl print "Content-Type: text/html\n\n"; print "hello world\n"; my ($sec, $min, $hour, $mday, $mon, $year) = localtime; $mon += 1; $year += 1900; print "$year-$mon-$mday $hour:$min:$sec\n"; !! SSL(TSL) 接続