- 2010-02-19
- html5
うちのOS X10.6でも無事動いたmod_websocketですが、
証明書の設定が面倒でwss(SSL)を試してみませんでした。
実際始めてしまえばそんなに面倒じゃないんですが、
やるまでがね…。
ってわけで、手順を残しておきますので、ご自由にどうぞ。
なお、参考にしたのは以下のサイトです。
Webサーバ「lighttpd」でSSLを使うには − @IT
今日も明日もググったー: lighttpd ssl
Rails + lighttpd + SSL - プログラマ 福重 伸太朗 〜基本へ帰ろう〜
作業ディレクトリへ
cd lighty/lighttpd-1.4.26
lighttpdをSSL ONでコンパイルし直し
./configure --prefix=/Users/t/lighty/ --with-openssl
(network-opensslがenableの方に表示されればOK)
make
make install
cd ..
lighttpdの設定
vi etc/lighttpd/lighttpd.conf
$SERVER["socket"] == ":8443" {
ssl.engine = "enable"
ssl.pemfile = "/Users/t/lighty/etc/lighttpd/ssl/server.pem"
}
:wq
※ ここではサボってますが、広く公開する場合等(っていうか原則)は、
ドキュメントルートを分けましょう。
オレオレ証明書の作成
mkdir etc/lighttpd/ssl/
openssl req -new -x509 -keyout server.pem -out server.pem
Generating a 1024 bit RSA private key
.........++++++
.............................++++++
writing new private key to 'server.pem'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
Verify failure
Enter PEM pass phrase:****
Verifying - Enter PEM pass phrase:****
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP
State or Province Name (full name) [Some-State]:Tokyo
Locality Name (eg, city) []:Koto
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Born Neet
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:localhost
Email Address []:
ls
server.pem
cd ~/lighty
起動
lighttpd -f etc/lighttpd/lighttpd.conf
Enter PEM pass phrase: ****
HTTPSのテスト(ブラウザから)
https://localhost:8443/
test
(証明書の警告は無視)
チャットサンプル(wss版)の準備
cp -p srv/www/htdocs/ws_chat.html srv/www/htdocs/wss_chat.html
vi srv/www/htdocs/wss_chat.html
var ws = new WebSocket("wss://127.0.0.1:8443/chat");
:wq
chatサーバの起動
mod_websocket/src/sample/ws_chat 9001
ポップアップが出るので許可する
Chatのテスト(Chromeから)
http://localhost:8080/wss_chat.html
https://localhost:8443/wss_chat.html
(wss通信だけじゃなくwss_chat.html取得の通信も暗号化すべき)
動いた!!
ん…wssってこれでいいんだっけ?
何か間違ってる気がするので突っ込みに期待…
…じゃなく後で勉強しとこう。
nori2048さんに早速突っ込みをいただきました。(2010/2/20 00:10)
コメント欄も合わせてご覧下さい。
(記事にも追記しています。)
- Newer: C言語(NW)とWebサーバのお勉強「Portable minimal web servers」を読む
- Older: mod_websocket for lighttpdをMacで動かしてみる2(無事成功!)
Comments:1
- @nori0428 2010-02-19 (金) 23:03
ありがとうございます、blog書くの苦手なので、導入記事書いていただけるの、とってもうれしいです:)
http://localhost:8080/wss_chat.html
これなんですが、早速突っ込みましょう。
server.port = 8080
$SERVER["socket"] == ":8443"
この場合、通常のhttpサーバとしてポート8080番で、httpsサーバとして8443番でListenしています。
ですので、
http://localhost:8080/wss_chat.html
この場合、wss_chat.htmlはhttp経由で取得され、wss_chat.html内部で生成されたWebSocketはhttps経由で繋がります。
両方httpsにする場合は、
https://localhost:8443/wss_chat.html
ですね。また、その場合には、$SERVER["socket"] == ":8443"ブロック内の、server.document-rootをhttpのdocument rootと分けておいたほうがわかりやすいかと思います:)
- tnantoka 2010-02-20 (土) 00:00
早速の突っ込みありがとうございます。
>ありがとうございます、blog書くの苦手なので、導入記事書いていただけるの、とってもうれしいです:)
こんなレベルの記事で良ければ、これからもよろしくお願いします。
>両方httpsにする場合は、
>https://localhost:8443/wss_chat.html
>ですね。
どちらもSSLにすべきでしたか。
サンプルとしてどちらがわかりやすいか迷ったんですが…。
「ページ自体はHTTPで、WebSocketsのやりとりだけ暗号化したい…」なんてケースはないでしょうから、どちらもHTTPSにしとくべきですよね。
>その場合には、$SERVER["socket"] == ":8443"ブロック内の、server.document-rootをhttpのdocument rootと分けておいたほうがわかりやすいかと思います:)
セキュリティ上も分けるべきですよね。
サボってすいません^^
Trackback+Pingback:0
- TrackBack URL for this entry
- Listed below are links to weblogs that reference
- mod_websocket for lighttpdをMacで動かしてみる3(ssl,wss) from Born Neet
