nginx 0.7 + wsgi on Gentoo
今の開発してるサービスは、nginx 0.6.36とかをつかって開発してたのですが、
ふと気がつくと、stableは0.7.60とかになってるので、nginxのアップデートをした。
もともとwsgiを使えるようにしたnginxのebuildを0.6系のために書いていたのだけれど、それでは0.7.60はコンパイルが通らないようになってた。
Gentoo BugZillaも見てみたけど、いまいちそのまま使えるebuildはなさげだったので、自分でpatchとebuildをでっち上げた。
とりあえず、動いてるようなんだけれども、これでいいかどうかはよーわからん。
とりあえず、ebuidとパッチを貼り付けてみる。USEフラグにpythonがはいってると、mod-wsgiが組み込まれる。
基本的には、もともとportageに含まれる0.7.*のものをコピーしてきて、
wsgiをadd-moduleしているだけ。
ただ、
ngx_conf_merge_path_valueの引数が変わってるので、他のモジュールから同じような感じでパクったパッチ
ngx_http_discard_bodyていう関数はないみたいなので、ngx_http_discard_request_bodyに変更したパッチ
(ちなみに、ngx_http_discard_request_bodyのほうのパッチは0.6系でも必要。)
というパッチをあてているだけ。
ぶっちゃけnginxのソースとか見ずに、適当に書き換えたので合っているかどうか不安だけど、
とりあえず問題なくうごいているよう。
ちなみに、このebuildはUSEフラグにsslがないとコンパイルに失敗する。
md5.hをさがすconfigureのところがおかしいっぽいけど、ssl使うしまあいいやってことで放置しているので注意。
wsgi serverとして、nginx以外の選択肢として、fapws3を試してみたけど、segfaultで落ちた。。。
さすがに今日はおっかける気力がなかったので、とりあえず放置。
まあ、なにはともあれ、nginx 0.7.60にアップデートできたのでよかったよかった。
nginx-0.7.60.ebuild
inherit eutils ssl-cert DESCRIPTION="Robust, small and high performance http and reverse proxy server" WSGIVER="8994b058d2db" HOMEPAGE="http://nginx.net/" SRC_URI="http://sysoev.ru/nginx/${P}.tar.gz" LICENSE="BSD" SLOT="0" KEYWORDS="amd64 ~ppc x86" IUSE="addition debug fastcgi flv imap pcre perl random-index ssl status sub webdav zlib python" DEPEND="dev-lang/perl dev-libs/openssl pcre? ( >=dev-libs/libpcre-4.2 ) ssl? ( dev-libs/openssl ) zlib? ( sys-libs/zlib ) perl? ( >=dev-lang/perl-5.8 )" pkg_setup() { ebegin "Creating nginx user and group" enewgroup nginx enewuser nginx -1 -1 /dev/null nginx eend ${?} } src_unpack() { unpack ${A} if use python ; then cd ${DISTDIR} wget "http://hg.mperillo.ath.cx/nginx/mod_wsgi/archive/${WSGIVER}.tar.gz" unpack ${WSGIVER}.tar.gz mv mod_wsgi-${WSGIVER} ${WORKDIR}/${P}/ cd ${WORKDIR}/${P}/mod_wsgi-${WSGIVER} epatch "${FILESDIR}/nginx-all-wsgi_handler.patch" epatch "${FILESDIR}/nginx-0.7.60-temp_path.patch" fi } src_compile() { local myconf # threads support is broken atm. # # if use threads; then # einfo # ewarn "threads support is experimental at the moment" # ewarn "do not use it on production systems - you've been warned" # einfo # myconf="${myconf} --with-threads" # fi use addition && myconf="${myconf} --with-http_addition_module" use fastcgi || myconf="${myconf} --without-http_fastcgi_module" use fastcgi && myconf="${myconf} --with-http_realip_module" use flv && myconf="${myconf} --with-http_flv_module" use zlib || myconf="${myconf} --without-http_gzip_module" use pcre || { myconf="${myconf} --without-pcre --without-http_rewrite_module" } use debug && myconf="${myconf} --with-debug" use ssl && myconf="${myconf} --with-http_ssl_module" use imap && myconf="${myconf} --with-imap" # pop3/imap4 proxy support use perl && myconf="${myconf} --with-http_perl_module" use status && myconf="${myconf} --with-http_stub_status_module" use webdav && myconf="${myconf} --with-http_dav_module" use sub && myconf="${myconf} --with-http_sub_module" use python && myconf="${myconf} --add-module=mod_wsgi-${WSGIVER}" use random-index && myconf="${myconf} --with-http_random_index_module" ./configure \ --prefix=/usr \ --conf-path=/etc/${PN}/${PN}.conf \ --http-log-path=/var/log/${PN}/access_log \ --error-log-path=/var/log/${PN}/error_log \ --pid-path=/var/run/${PN}.pid \ --http-client-body-temp-path=/var/tmp/${PN}/client \ --http-proxy-temp-path=/var/tmp/${PN}/proxy \ --http-fastcgi-temp-path=/var/tmp/${PN}/fastcgi \ --with-md5-asm --with-md5=/usr/include \ --with-sha1-asm --with-sha1=/usr/include \ ${myconf} || die "configure failed" emake || die "failed to compile" } src_install() { keepdir /var/log/${PN} /var/tmp/${PN}/{client,proxy,fastcgi} dosbin objs/nginx cp "${FILESDIR}"/nginx-r1 "${T}"/nginx doinitd "${T}"/nginx cp "${FILESDIR}"/nginx.conf-r4 conf/nginx.conf dodir "${ROOT}"/etc/${PN} insinto "${ROOT}"/etc/${PN} doins conf/* dodoc CHANGES{,.ru} README use perl && { cd "${S}"/objs/src/http/modules/perl/ einstall DESTDIR="${D}"|| die "failed to install perl stuff" } } pkg_postinst() { use ssl && { if [ ! -f "${ROOT}"/etc/ssl/${PN}/${PN}.key ]; then dodir "${ROOT}"/etc/ssl/${PN} insinto "${ROOT}"etc/ssl/${PN}/ insopts -m0644 -o nginx -g nginx install_cert /etc/ssl/nginx/nginx fi } }
nginx-0.7.60-temp_path.patch
--- mod_wsgi-8994b058d2db/src/ngx_http_wsgi_module.c 2008-03-27 04:35:15.000000000 +0900 +++ /tmp/nginx-0.7.60.new/mod_wsgi-8994b058d2db/src/ngx_http_wsgi_module.c 2009-06-19 16:1 3:52.000000000 +0900 @@ -62,6 +62,10 @@ static ngx_conf_enum_t ngx_http_wsgi_re { ngx_null_string, 0 } }; +static ngx_path_init_t ngx_http_wsgi_temp_path = { + ngx_string(NGX_HTTP_WSGI_TEMP_PATH), { 1, 2, 0 } +}; + static ngx_command_t ngx_http_wsgi_commands[] = { /* main configuration commands */ @@ -156,7 +160,7 @@ static ngx_command_t ngx_http_wsgi_comm ngx_conf_set_path_slot, NGX_HTTP_LOC_CONF_OFFSET, offsetof(ngx_http_wsgi_loc_conf_t, temp_path), - (void *) ngx_garbage_collector_temp_handler }, + NULL }, { ngx_string("wsgi_var"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, @@ -342,10 +346,11 @@ ngx_http_wsgi_merge_loc_conf(ngx_conf_t ngx_conf_merge_size_value(conf->write_buffer_size, prev->write_buffer_size, (size_t) ngx_pagesize); - ngx_conf_merge_path_value(conf->temp_path, + ngx_conf_merge_path_value(cf, &conf->temp_path, prev->temp_path, - NGX_HTTP_WSGI_TEMP_PATH, 1, 2, 0, - ngx_garbage_collector_temp_handler, cf); + &ngx_http_wsgi_temp_path); +// NGX_HTTP_WSGI_TEMP_PATH, 1, 2, 0, +// ngx_garbage_collector_temp_handler, cf); ngx_conf_merge_value(conf->use_main_interpreter, prev->use_main_interpreter, 0);
nginx-all-wsgi_handler.patch
diff -pruN mod_wsgi-8994b058d2db/src/ngx_http_wsgi_handler.c mod_wsgi-8994b058d2db-new/src/ngx_ http_wsgi_handler.c --- mod_wsgi-8994b058d2db/src/ngx_http_wsgi_handler.c 2008-03-27 04:35:15.000000000 +0900 +++ mod_wsgi-8994b058d2db-new/src/ngx_http_wsgi_handler.c 2009-04-13 17:01:17.000000000 + 0900 @@ -71,7 +71,7 @@ ngx_http_wsgi_handler(ngx_http_request_t if (r->method == NGX_HTTP_GET || r->method == NGX_HTTP_HEAD) { /* XXX not sure */ - rc = ngx_http_discard_body(r); + rc = ngx_http_discard_request_body(r); if (rc != NGX_OK && rc != NGX_AGAIN) { return rc;
手持ちマシン
- Core Solo U1300: -march=prescott --param l1-cache-size=32 --param l1-cache-line-size=64
- Core2Duo E6300: -march=core2 -mcx16 -msahf --param l1-cache-size=32 --param l1-cache-line-size=64 -mtune=core2
- Q9550s: -march=core2 -mcx16 -msahf --param l1-cache-size=32 --param l1-cache-line-size=64 -mtune=core2
という結果になった。
gcc 4.3系のいいところ
- 4.2からできた気がするけど、--march=nativeが指定できる。
- CFLAGSを考えなくていいのは楽でよいよい。
- コンパイルはやくなった?
ちなみに、nativeを指定したときに、どんなCFLAGSになっているかは、
http://d.hatena.ne.jp/tmatsuu/20090110/1231557035
に記載のもので調べられる。
基本手順
わりと簡単。
1. gcc,glibcの~x86のマスクをはずす
(/etc/portage/package.keywordsに書くとか)
=sys-devel/gcc-4.3.2-r3 -x86 ~x86 =sys-libs/glibc-2.9_p20081201-r2 -x86 ~x86
こんな感じかな。
バージョンは指定しなくてもいいけど、まあ、とりあえず、指定している。
2. emerge -uav gcc glibc
とすると、インストールが始まる。
3. gcc切替
# gcc-config -l # gcc-config 2
gcc-configで4.3のものに切り替えます。
4. /etc/profileのリロード
# source /etc/profile
5. 古いgccを消す(4.1.2)
消さないと、次の手順でこけた。gcc 4.1.2はgcc 4.3.2ではコンパイルできないらしい。
6./etc/make.confのCFLAGSを変える
CFLAGS="-O2 -march=native -pipe"
にとりあえずした。
7. 最後に、全部コンパイルし直し
# emerge -eDNav world
これで、再起動すると、gcc 4.3のバイナリに入れ替わる!
Windows 7をKVMで動かした。
とりあえず、32bit 日本語版であれば、なんの問題もなく動作した。
インストール時は、こんな感じのコマンド。
~/kvm/bin/qemu-system-x86_64 \ -vga cirrus \ -m 2048m -monitor stdio -curses -vnc :11 \ -soundhw ac97 \ -usbdevice tablet \ -localtime -k ja \ -net nic,vlan=0,model=e1000,macaddr=52:54:00:12:34:61 \ -net tap,vlan=0,ifname=qtap11,script=no \ -cdrom install_image/7000.0.081212-1400_client_ja-jp_Ultimate-GB1CULFRE_JA_DVD.iso \ -drive file=hdd_image/win7-gohan.img,if=ide,boot=on
とりあえず、
- cirrus
- ac97
- e1000
- ide
という一番、無難そうなデバイスの組み合わせでインストールした。
特に問題なくインストールできた。
んで、NICはvirtioに変更して、最近リリースされた
Windows版のvirtio-netのドライバをもってきて、vista向けのものをインストールすると、問題なく動く。
ちなみに、このバージョンからいろんなオプションがプロパティで設定できるようになった。LinkSpeedとか。
cirrusのドライバも標準ドライバから、こっちのドライバに変える。
こっちも問題なく入った。
これで、一応、インストールは完了。当然、Aeroとかはうごかんけど、リモートデスクトップから普通に使える。
検証用途ならこれで十分かな。