QUIC対応版nginxが出ていたのでビルドとRPMパッケージを作成した。

www.nginx.co.jp

先月くらいにnginxのQUIC preview版が出ていましたので今更ながら試してみました。

coprで作ったのでお試しください。(既存のnginxを上書きするのでご注意ください。)

https://copr.fedorainfracloud.org/coprs/ryoh/nginx-quic/

まずnginxをビルドしなければいけませんが、そのあたりはこちらの方の記事の通りに行うだけでできました。

asnokaze.hatenablog.com

今回は他の環境でも使いやすいようRPMパッケージを作成します。

RPMパッケージ作成についてですが、基本は記事の通りBoringSSLとnginx-quicを使ってビルドするだけです。

ただ、パッケージを作るタイミングでファイルの状態が変わると安定性がないため、HEADからではなくハッシュ値からファイルを取得します。

nginxもBoringSSLもMercurialなので下記のような形でファイルを取得します。

https://hg.nginx.org/nginx-quic/archive/コミットのハッシュ値.tar.gz

ここ以外はあまり変わらず、こんな感じでSPECファイルを作成してRPMパッケージを作るだけです。
(詳細は下記僕のレポジトリをご参照ください。)

https://github.com/ryoh/nginx-quic.spec

Name:           nginx-quic
Version:        1.19.1
Release:        0%{?dist}
Summary:        A high performance web server and reverse proxy
Group:          System Environment/Daemons 
License:        BSD
URL:            https://nginx.org/

Source0:        https://hg.nginx.org/nginx-quic/archive/e533a352d118.tar.gz
Source100:      https://boringssl.googlesource.com/boringssl/+archive/54858b63c1d886f6c8d903d4a4f594f1485de189.tar.gz

%description
nginx [engine x] is an HTTP and reverse proxy server, a mail proxy server,
and a generic TCP/UDP proxy server, originally written by Igor Sysoev.

%prep
%setup -q -n %{name}-e533a352d118

pushd ..
%{__rm} -rf boringssl
%{__mkdir} boringssl
cd boringssl
%{__tar} -xf %{SOURCE100}
popd

%build
pushd ../boringssl
mkdir build
cd build
cmake3 -GNinja ..
ninja

cd ..
mkdir -p .openssl/lib
cd .openssl
ln -s ../include .
cd ..
cp build/crypto/libcrypto.a build/ssl/libssl.a .openssl/lib
popd

./auto/configure \
  --with-debug \
  --with-cc-opt="-I../boringssl/include" \
  --with-ld-opt="-L../boringssl/build/ssl -L../boringssl/build/crypto" \
  --with-http_v3_module \

%make_build

%install
[[ -d %{buildroot} ]] && rm -rf "%{buildroot}"
%{__mkdir} -p "%{buildroot}"
%make_install INSTALLDIRS=vendor

unlink %{buildroot}/etc/nginx/koi-utf
unlink %{buildroot}/etc/nginx/koi-win
unlink %{buildroot}/etc/nginx/win-utf

%files
%defattr(-,root,root)
/usr/sbin/nginx

%config(noreplace) /etc/nginx/nginx.conf
%config(noreplace) /etc/nginx/mime.types
%config(noreplace) /etc/nginx/fastcgi_params
%config(noreplace) /etc/nginx/scgi_params
%config(noreplace) /etc/nginx/uwsgi_params

%changelog

あとはこのパッケージに対してファイルを取得して、RPMパッケージをビルドするだけです。

spectool -g -R SPECS/nginx-quic.spec
rpmbuild -ba SPECS/nginx-quic.spec

作成したRPMパッケージを他の環境などに持っていきyumコマンドでインストールすれば利用可能です。

yum install RPMS/x86_64/nginx-quic-1.19.1-1.el7.rpm

SRPMをCOPRというサービスに持っていけば、簡易な自分のレポジトリができます。(UbuntuのPPAのような)

https://copr.fedorainfracloud.org/coprs/ryoh/nginx-quic/

yum copr enable ryoh/nginx-quic
yum install nginx-quic

最近だとDockerで作ったほうが簡単そうですが、Redhat, CentOSに限ればこういう配布方法もあるよ、という話でした。