20
30

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

nginxインストール(ソースからビルド編)for RockyLinux9.5

Last updated at Posted at 2016-09-18

概要

Apacheと共に最近人気なnginxをソースからビルドして導入したいと思います。
2025年4月現在では、「1.27.4」が最新版

ダウンロード先

ダウンロード先は
http://nginx.org/download/
で確認が可能

注意事項

OpenSSLは、あらかじめコンパイルをしておきます。
また、includeの関係でソースが必要ですので、opensslのsrcディレクトリを指定します。
今回は「/usr/local/src/」に「openssl-1.1.1l.tar.gz」を回答したものを配置し、そのディレクトリを「--with-openssl」で指定します。
OpenSSLに関しては、「Rocky Linux 9.4にOpenSSL 3.4をインストールする(ソースからビルド)」を参照してください。

検証環境バージョン

ソフトウェア バージョン
PCRE  8.45
nginx 1.21.3
OS RockyLinux 8.4

事前準備(必要なライブラリを入れる)

dnf install zlib-devel

PCRE2のインストール

まずは、PCREをインストール

cd /usr/local/src
wget https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.45/pcre2-10.45.tar.gz
tar xvzf pcre2-10.45.tar.gz
cd pcre2-10.45
./configure
make -j 8
make install

nginxのインストール

nginxダウンロードとインストール
cd /usr/local/src
wget https://nginx.org/download/nginx-1.27.4.tar.gz
tar xvzf nginx-1.27.4.tar.gz
cd nginx-1.27.4
./configure --prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--with-pcre-jit \
--with-http_addition_module \
--with-http_dav_module \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_sub_module \
--with-mail \
--with-mail_ssl_module \
--with-openssl=/usr/local/src/openssl-3.4.1
make
make install

# 非推奨オプション
# --with-http_xslt_module \
# --with-ipv6 \
# --with-sha1=/usr/local \
# --with-md5=/usr/local \

/usr/sbin/nginx が存在すればコンパイル完了です。

起動スクリプトの配置

起動スクリプトは、CentOSのRPMから拝借しましょう。

nginx起動スクリプト配置先
/usr/lib/systemd/system/nginx.service
nginx起動スクリプト
cat > /usr/lib/systemd/system/nginx.service << EOF
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
 
[Service]
Type=forking
PIDFile=/etc/nginx/logs/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/conf/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP \$MAINPID
ExecStop=/bin/kill -s QUIT \$MAINPID
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

EOF

起動スクリプトの設定

あとは、このスクリプトで起動と停止を確認

nginx起動
systemctl start nginx
nginx停止
systemctl stop nginx
nginx自動起動
systemctl enable nginx
20
30
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
30

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?