Ubuntu10.04でdpkgを使って、Nginxにモジュールを追加する

前回の記事で、Nginxにサードパーティモジュールを追加してコンパイルしてインストールする手順を書きましたが、Ubuntu(Debian)の作法に乗っ取ってdpkgを使うと、もっと簡単にモジュール追加ができるのでその手順もメモしておきます。

dpkg-devのインストール、Nginxのコンパイルに必要なライブラリのインストール、Nginxのソースの取得まで

$ sudo apt-get install dpkg-dev
$ sudo apt-get update
$ sudo apt-get build-dep nginx
$ apt-get source nginx
$ cd nginx-0.7.65

追加するモジュールは、AWS Authを追加したいのでgitをコマンドを入れて、モジュールのソースコードを取得

$ sudo apt-get install git-core
$ git clone https://github.com/anomalizer/ngx_aws_auth.git

モジュールをconfigureに指定

$ vi debian/rules 
..
    ./configure --conf-path=/etc/nginx/nginx.conf \
        --error-log-path=/var/log/nginx/error.log \
        --pid-path=/var/run/nginx.pid \
        --lock-path=/var/lock/nginx.lock \
        --http-log-path=/var/log/nginx/access.log \
        --http-client-body-temp-path=/var/lib/nginx/body \
        --http-proxy-temp-path=/var/lib/nginx/proxy \
        --http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
        --with-debug \
        --with-http_stub_status_module \
        --with-http_flv_module \
        --with-http_ssl_module \
        --with-http_dav_module \
        --with-http_gzip_static_module \
        --with-http_realip_module \
        --with-mail \
        --with-mail_ssl_module \
        --with-ipv6 \
        --add-module=$(CURDIR)/modules/nginx-upstream-fair \
        --add-module=$(CURDIR)/anomalizer-ngx_aws_auth-37adfc3/
        --add-module=$(CURDIR)/ngx_aws_auth \
            $(CONFIGURE_OPTS)
...

コンパイルして、パッケージを作成

$ dpkg-buildpackage -b
...
gcc -c -Wall -g -O2   -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules -I src/mail \
        -o objs/addon/anomalizer-ngx_aws_auth-37adfc3/ngx_http_aws_auth.o \
        /root/nginx-0.7.65/anomalizer-ngx_aws_auth-37adfc3//ngx_http_aws_auth.c
gcc -c -Wall -g -O2  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
        -o objs/ngx_modules.o \
        objs/ngx_modules.c
gcc -o objs/nginx \
    objs/src/core/nginx.o \
    objs/src/core/ngx_log.o \
    objs/src/core/ngx_palloc.o \
    objs/src/core/ngx_array.o \
    objs/src/core/ngx_list.o \
    objs/src/core/ngx_hash.o \
    objs/src/core/ngx_buf.o \
    objs/src/core/ngx_queue.o \
    objs/src/core/ngx_output_chain.o \
    objs/src/core/ngx_string.o \
    objs/src/core/ngx_parse.o \
    objs/src/core/ngx_inet.o \
    objs/src/core/ngx_file.o \
    objs/src/core/ngx_crc32.o \
    objs/src/core/ngx_rbtree.o \
    objs/src/core/ngx_radix_tree.o \
    objs/src/core/ngx_slab.o \
    objs/src/core/ngx_times.o \
    objs/src/core/ngx_shmtx.o \
    objs/src/core/ngx_connection.o \
    objs/src/core/ngx_cycle.o \
    objs/src/core/ngx_spinlock.o \
    objs/src/core/ngx_cpuinfo.o \
    objs/src/core/ngx_conf_file.o \
    objs/src/core/ngx_resolver.o \
    objs/src/core/ngx_open_file_cache.o \
    objs/src/event/ngx_event.o \
    objs/src/event/ngx_event_timer.o \
    objs/src/event/ngx_event_posted.o \
    objs/src/event/ngx_event_busy_lock.o \
    objs/src/event/ngx_event_accept.o \
    objs/src/event/ngx_event_connect.o \
    objs/src/event/ngx_event_pipe.o \
    objs/src/os/unix/ngx_time.o \
    objs/src/os/unix/ngx_errno.o \
    objs/src/os/unix/ngx_alloc.o \
    objs/src/os/unix/ngx_files.o \
    objs/src/os/unix/ngx_socket.o \
    objs/src/os/unix/ngx_recv.o \
    objs/src/os/unix/ngx_readv_chain.o \
    objs/src/os/unix/ngx_udp_recv.o \
    objs/src/os/unix/ngx_send.o \
    objs/src/os/unix/ngx_writev_chain.o \
    objs/src/os/unix/ngx_channel.o \
    objs/src/os/unix/ngx_shmem.o \
    objs/src/os/unix/ngx_process.o \
    objs/src/os/unix/ngx_daemon.o \
    objs/src/os/unix/ngx_setproctitle.o \
    objs/src/os/unix/ngx_posix_init.o \
    objs/src/os/unix/ngx_user.o \
    objs/src/os/unix/ngx_process_cycle.o \
    objs/src/os/unix/ngx_linux_init.o \
    objs/src/event/modules/ngx_epoll_module.o \
    objs/src/os/unix/ngx_linux_sendfile_chain.o \
    objs/src/event/ngx_event_openssl.o \
    objs/src/core/ngx_regex.o \
    objs/src/http/ngx_http.o \
    objs/src/http/ngx_http_core_module.o \
    objs/src/http/ngx_http_special_response.o \
    objs/src/http/ngx_http_request.o \
    objs/src/http/ngx_http_parse.o \
    objs/src/http/ngx_http_header_filter_module.o \
    objs/src/http/ngx_http_write_filter_module.o \
    objs/src/http/ngx_http_copy_filter_module.o \
    objs/src/http/modules/ngx_http_log_module.o \
    objs/src/http/ngx_http_request_body.o \
    objs/src/http/ngx_http_variables.o \
    objs/src/http/ngx_http_script.o \
    objs/src/http/ngx_http_upstream.o \
    objs/src/http/ngx_http_upstream_round_robin.o \
    objs/src/http/ngx_http_parse_time.o \
    objs/src/http/modules/ngx_http_static_module.o \
    objs/src/http/modules/ngx_http_index_module.o \
    objs/src/http/modules/ngx_http_chunked_filter_module.o \
    objs/src/http/modules/ngx_http_range_filter_module.o \
    objs/src/http/modules/ngx_http_headers_filter_module.o \
    objs/src/http/modules/ngx_http_not_modified_filter_module.o \
    objs/src/http/ngx_http_busy_lock.o \
    objs/src/http/ngx_http_file_cache.o \
    objs/src/http/modules/ngx_http_gzip_filter_module.o \
    objs/src/http/ngx_http_postpone_filter_module.o \
    objs/src/http/modules/ngx_http_charset_filter_module.o \
    objs/src/http/modules/ngx_http_ssi_filter_module.o \
    objs/src/http/modules/ngx_http_userid_filter_module.o \
    objs/src/http/modules/ngx_http_gzip_static_module.o \
    objs/src/http/modules/ngx_http_dav_module.o \
    objs/src/http/modules/ngx_http_autoindex_module.o \
    objs/src/http/modules/ngx_http_auth_basic_module.o \
    objs/src/http/modules/ngx_http_access_module.o \
    objs/src/http/modules/ngx_http_limit_zone_module.o \
    objs/src/http/modules/ngx_http_limit_req_module.o \
    objs/src/http/modules/ngx_http_realip_module.o \
    objs/src/http/modules/ngx_http_geo_module.o \
    objs/src/http/modules/ngx_http_map_module.o \
    objs/src/http/modules/ngx_http_referer_module.o \
    objs/src/http/modules/ngx_http_rewrite_module.o \
    objs/src/http/modules/ngx_http_ssl_module.o \
    objs/src/http/modules/ngx_http_proxy_module.o \
    objs/src/http/modules/ngx_http_fastcgi_module.o \
    objs/src/http/modules/ngx_http_memcached_module.o \
    objs/src/http/modules/ngx_http_empty_gif_module.o \
    objs/src/http/modules/ngx_http_browser_module.o \
    objs/src/http/modules/ngx_http_flv_module.o \
    objs/src/http/modules/ngx_http_upstream_ip_hash_module.o \
    objs/src/http/modules/ngx_http_stub_status_module.o \
    objs/src/mail/ngx_mail.o \
    objs/src/mail/ngx_mail_core_module.o \
    objs/src/mail/ngx_mail_handler.o \
    objs/src/mail/ngx_mail_parse.o \
    objs/src/mail/ngx_mail_ssl_module.o \
    objs/src/mail/ngx_mail_pop3_module.o \
    objs/src/mail/ngx_mail_pop3_handler.o \
    objs/src/mail/ngx_mail_imap_module.o \
    objs/src/mail/ngx_mail_imap_handler.o \
    objs/src/mail/ngx_mail_smtp_module.o \
    objs/src/mail/ngx_mail_smtp_handler.o \
    objs/src/mail/ngx_mail_auth_http_module.o \
    objs/src/mail/ngx_mail_proxy_module.o \
    objs/addon/nginx-upstream-fair/ngx_http_upstream_fair_module.o \
    objs/addon/anomalizer-ngx_aws_auth-37adfc3/ngx_http_aws_auth.o \
    objs/ngx_modules.o \
    -lcrypt -lssl -lpcre -lssl -lcrypto -lz
...

debパッケージをインストール

$ cd ..
$ sudo dpkg -i nginx_0.7.65-1ubuntu2.3_amd64.deb 

サーバー再起動

$sudo  service nginx restart

非常に簡単です。

参考にしたサイト: