既存のNginxに画像変換用のNginxモジュールである ngx_small_ligth を追加する必要があったので、その手順のメモ
Nginx は yum でインストールしている想定
$ vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
$ yum install nginx
環境
- CentOS Linux release 7.6.1810 (Core)
- Nginx 1.14.2 (2019/2/6時点でのstable)
事前準備
Nginxのバージョンを確認しておく
$ nginx -V
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
とりあえず必要そうなものをインストール
# nginxを使った動的モジュールのビルドに必要
$ yum install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
# ngx_small_light のビルドに必要
$ yum install ImageMagick ImageMagick-devel
$ yum install git
# vimないとつらいので
$ yum install vim
Nginxのソースのダウンロード
http://nginx.org/en/download.html からyumで入れたバージョンと同じNginxのソースを落としてくる
$ curl -O http://nginx.org/download/nginx-1.14.2.tar.gz
$ tar xzvf nginx-1.14.2.tar.gz
ngx_small_lighをclone
git でcloneしてくる
$ cd nginx-1.14.2
$ git clone https://github.com/cubicdaiya/ngx_small_light
ngx_small_lightのセットアップ
$ cd ngx_small_light
$ ./setup
config is generated.
ngx_small_light の動的モジュールのビルド
# nginxのディレクトリに戻る
$ cd ..
# 引数 --add-dynamic-module=./ngx_small_light をつけて ./configure を行う
# nginxをビルドしたときと同じ引数を指定する必要があるため
# nginx -V で表示された引数も追加する
$ ./configure --add-dynamic-module=./ngx_small_light \
--prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
# モジュールのビルド
$ make modules
# objs/ 以下にビルドされたsoファイルがあるので、コピー
$ cp objs/ngx_http_small_light_module.so /usr/lib64/nginx/modules
Nginx でのモジュールの読み込み
/etc/nginx/nginx.conf
に以下を追加
nginx.conf
load_module /usr/lib64/nginx/modules/ngx_http_small_light_module.so;
/etc/nginx/conf.d/default.conf
に以下を追加
default.conf
small_light on;
起動してエラーがでなければ、OK