ラズパイ上のCentOS7にnginxを入れる

  • LINEで送る

私の覚書です。

Linux向けのパッケージが提供されているのですが、CentOSのarm向けのものはないので、ソースから導入します。

Debian向けにはarmがあったので、Raspbianとかならパッケージを入れられるはずです。
 

こちらからバージョンを確認して、tarのurlを確認します。
今回はStable versionが1.14.0でしたので、これを使用します。

wgetして解凍します。

raspi2 ~ % wget https://nginx.org/download/nginx-1.14.0.tar.gz
raspi2 ~ % ls
nginx-1.14.0.tar.gz
raspi2 ~ % tar xzf nginx-1.14.0.tar.gz
raspi2 ~ % rm -f nginx-1.14.0.tar.gz
raspi2 ~ % cd nginx-1.14.0
raspi2 ~/nginx-1.14.0 % ls
CHANGES  CHANGES.ru  LICENSE  README  auto/  conf/  configure*  contrib/  html/  man/  src/

コンパイルに必要なパッケージを入れます。

raspi2 ~/nginx-1.14.0 % sudo yum install pcre-devel zlib-devel

インストールします。

raspi2 ~/nginx-1.14.0 % ./configure && make && sudo make install

 

起動と自動起動

systemdで管理できるようにunitファイルを作成します。
armではないcentos7にパッケージからインストールしたnginx用のunitファイルを流用します。

raspi2 ~/nginx-1.14.0 % sudo -e /usr/lib/systemd/system/nginx.service
raspi2 ~/nginx-1.14.0 % cat /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

自動起動

raspi2 ~/nginx-1.14.0 % sudo systemctl daemon-reload
raspi2 ~/nginx-1.14.0 % sudo systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

起動

raspi2 ~/nginx-1.14.0 % sudo systemctl start nginx
raspi2 ~/nginx-1.14.0 % sudo systemctl status nginx
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since 水 2018-09-12 20:43:49 JST; 7s ago
     Docs: http://nginx.org/en/docs/
  Process: 4276 ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 4277 (nginx)
   CGroup: /system.slice/nginx.service
           ├─4277 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
           └─4278 nginx: worker process
...

 
わーい

  • LINEで送る

SNSでもご購読できます。

コメントを残す

*