0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【1.21.1】Nginx 最新バージョン のソースビルド 【CentOS】

Last updated at Posted at 2021-09-02

Nginxのインストール方法

特に難しいことはなかったけどメモ

環境

  • OS : CentOS Stream 8
  • Cloud : GCP GCE
  • Nginx : 1.21.2 (2021.09.02 最新)

手順

【参考】公式手順

1. tar を DL

# cd /usr/local/src
# wget https://nginx.org/download/nginx-1.21.2.tar.gz

2. tar 解凍

# tar xzvf nginx-1.21.2.tar.gz
# rm nginx-1.21.2.tar.gz
# cd nginx-1.21.2

3. ./configure

# ./configure
...
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

ここでエラー
pcre のライブラリが必要らしい

  • pcre-develをインストール

ggったらこれで解決している人がいたので。

# dnf install pcre-devel

4. make

# make

5. make install

# make install

6. パスを通す

# ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx

# nginx -v
nginx version: nginx/1.21.2

Daemon化手順

ソースインストールだとsystemctlで操作できないのでデーモン化する
といっても/lib/systemd/system/にファイル作成するだけ

手順

  • serviceファイル作成
nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

今回の手順だとPIDFILEが/usr/local/nginx/logs/nginx.pid になって起動できないので、
nginx.confで設定変更する

nginx.conf
pid        /var/run/nginx.pid;

コメントアウトを外して、/var/run/nginx.pid (もしくは /run/nginx.pid)にする

  • 起動確認
# systemctl start nginx
# systemctl status nginx
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?