1
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?

最短10秒でWindowsにWebサーバーを建てる

Posted at

久々の投稿です。

Webサーバー構築RTAです。

静的ファイルサーバー

curl -L https://frippery.org/files/busybox/busybox64u.exe > .\busybox.exe
.\busybox.exe sh
httpd -fv -p 127.0.0.1:9999 -h ./

http://127.0.0.1:9999 からローカルファイルが公開されます。

動的CGIサーバー

curl -L https://frippery.org/files/busybox/busybox64u.exe > .\busybox.exe
.\busybox.exe sh
mkdir -p ./www/cgi-bin
echo -ne '<div>hello! <a href="./cgi-bin/random">random</a></div>' > ./www/index.html
echo -ne '#!/bin/sh\nset -eu\necho "Content-Type: text/plain"\necho\necho ${RANDOM}' > ./www/cgi-bin/random
httpd -fv -p 127.0.0.1:9999 -h ./www

http://127.0.0.1:9999 から index.html が公開されます。
http://127.0.0.1:9999/cgi-bin/random からアクセス毎にランダムな整数を取得できます。

解説

busybox-w32 をダウンロードして sh から httpd を実行するだけ。

以前は静的サーバーのみでしたが、最近のアップデートでCGIに対応しました。
公開ルートディレクトリ (-h) に httpd.conf を置くと認証やアクセス制御が可能です。

本番運用には向きませんが、作業や社内公開であれば充分すぎる機能です。

CMD君はBusyBoxをダウンロードする為だけの存在です。Edge君と同じだね。

busybox-w32

偉大なるbusybox-w32をざっくりおさらい。

  • 本家BusyBox(Linux)のWindows移植版
  • 本家機能をほぼカバー
  • 依存関係無
  • シングルバイナリ
  • 省ファイルサイズ (v5467で658kB)
  • bash(ash)内蔵でShellScript実行可能

とりあえずbusybox-w32を C:\Windows あたりに突っ込んでおけば、巨大で煩雑なCigwinやWSL2を導入せずに、シンプルで強力なUnixLike環境を簡単に用意できます。
僕はもうbusybox-w32を無くしてWindowsで作業できない身体になってしまいました。

1
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
1
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?