nginx headerを書き換える
http://wiki.nginx.org/HttpHeadersMoreModule#more_set_headers
* headers-more-nginx-moduleの最新版をダウンロードして
https://github.com/agentzh/headers-more-nginx-module/tags
0.19をダウンロードして展開。
/path/to/headers-more-nginx-module-0.19
* インストール
centos 6用のソースを利用するため
http://nginx.org/packages/centos/6/SRPMS/nginx-1.2.7-1.el6.ngx.src.rpm
をダウンロードしておきます。
# rpm -ivh nginx-1.2.7-1.el6.ngx.src.rpm
警告: nginx-release-centos-6-0.el6.ngx.src.rpm: ヘッダ V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
########################################### [100%]
specファイルを編集
# vim /root/rpmbuild/SPECS/nginx.spec
オプション設定部分に
–add-module=/path/to/headers-more-nginx-module
を追加します。
./configure \
–prefix=%{_sysconfdir}/nginx \
–sbin-path=%{_sbindir}/nginx \
–conf-path=%{_sysconfdir}/nginx/nginx.conf \
–error-log-path=%{_localstatedir}/log/nginx/error.log \
–http-log-path=%{_localstatedir}/log/nginx/access.log \
–pid-path=%{_localstatedir}/run/nginx.pid \
–lock-path=%{_localstatedir}/run/nginx.lock \
–http-client-body-temp-path=%{_localstatedir}/cache/nginx/client_temp \
–http-proxy-temp-path=%{_localstatedir}/cache/nginx/proxy_temp \
–http-fastcgi-temp-path=%{_localstatedir}/cache/nginx/fastcgi_temp \
–http-uwsgi-temp-path=%{_localstatedir}/cache/nginx/uwsgi_temp \
–http-scgi-temp-path=%{_localstatedir}/cache/nginx/scgi_temp \
–user=%{nginx_user} \
–group=%{nginx_group} \
–with-http_ssl_module \
–with-http_realip_module \
–with-http_addition_module \
–with-http_sub_module \
–with-http_dav_module \
–with-http_flv_module \
–with-http_mp4_module \
–with-http_gzip_static_module \
–with-http_random_index_module \
–with-http_secure_link_module \
–with-http_stub_status_module \
–with-mail \
–with-mail_ssl_module \
–with-file-aio \
–with-ipv6 \
–with-debug \
/* 略 */
–add-module=/path/to/headers-more-nginx-module
* rpmbuild
rpmbuild -bb nginx.spec
書き込み完了: /path/RPMS/x86_64/nginx-1.2.7-1.el6.ngx.x86_64.rpm
書き込み完了: /path/rpmbuild/RPMS/x86_64/nginx-debug-1.2.7-1.el6.ngx.x86_64.rpm
書き込み完了: /path/rpmbuild/RPMS/x86_64/nginx-debuginfo-1.2.7-1.el6.ngx.x86_64.rpm
こんな感じで完了。
* yumでいれたnginxをuninstallしておく。
* nginx-1.2.7-1.el6.ngx.x86_64.rpmをインストールする。
同じ構成のサーバーはこれを入れるだけなので楽です。
# rpm -ivh nginx-1.2.7-1.el6.ngx.x86_64.rpm
準備中… ########################################### [100%]
1:nginx ########################################### [100%]
———————————————————————-
Thanks for using NGINX!
* nginx を start
* test
Server:nginx/1.2.7
ちゃんと更新されました。
* ヘッダーを変更してみる
more_set_headers -s 200 ‘Status: 200′;
more_set_headers ‘Content-Type: text/plain';
proxy_pass http://app_servers;
}
ちゃんと更新されました。
Content-Type:text/plain; charset=UTF-8
Date:Sun, 24 Feb 2013 10:40:23 GMT
Server:nginx
Status:200