LoginSignup
1
0

More than 5 years have passed since last update.

Raspbinan JessieLite にnginx 1.10をソースビルドインストールする

Last updated at Posted at 2017-01-23

過去記事:nginxの出力先をカスタマイズする

概要

Raspberry Piにphpサーバを立てたくて、まずWebサーバとしてNginxをインストールします。
自分が前に書いたことを思い出しながら、やってます。

環境

バージョン
OS Raspbian Jessie Lite
Webサーバ Nginx 1.10.2

目指す構成

実行本体とドキュメントを分離して、一時的なものは全てtemp配下で細かく分ける様にします。

${NGINX_ROOT}
   +---1.10.2
       +--sbin
       +--conf
    +---running
        +--logs
        +--html
        +--temp
           +-client_body_temp
           +-proxy_temp
           +-fastcgi_temp
           +-uwsgi_temp
           +-scgi_temp
(デフォルトでは~_tempのディレクトリがlogsとかと一緒の場所に作成されてしまい、
 htmlとかlogsの存在が埋もれてしまいそうになる。)

インストール

アカウント作成

$ sudo bash
$ mkdir /opt/nginx
$ groupadd -r web
$ useradd -r -g web -d /opt/nginx -s /usr/sbin/nologin nginx
$ chown -R nginx:web /opt/nginx
$ exit

PCREのインストール

$ wget https://ftp.pcre.org/pub/pcre/pcre-8.39.tar.gz
$ tar zxf pcre-8.39.tar.gz
$ ./configure
$ make
$ sudo porg -lD make install

コンパイル時に必要となるライブラリを入れておきます

ソースダウンロード&解凍

$ wget https://nginx.org/download/nginx-1.10.2.tar.gz
$ tar xzf nginx-1.10.2.tar.gz

コンパイル&インストール

$ cd ./nginx-1.10.2/
$ ./configure --user=nginx --group=web \
    --with-http_ssl_module \
    --with-http_random_index_module \
    --with-http_dav_module \
    --without-select_module \
    --with-pcre=/home/pi/pcre-8.39 \
    --prefix=/opt/nginx/running \
    --sbin-path=/opt/nginx/1.10.2/sbin/nginx \
    --conf-path=/opt/nginx/1.10.2/conf/nginx.conf \
    --pid-path=/var/run/nginx.pid \
    --lock-path=/var/lock/subsys/nginx \
    --http-client-body-temp-path=temp/client_body_temp \
    --http-proxy-temp-path=temp/proxy_temp \
    --http-fastcgi-temp-path=temp/fastcgi_temp \
    --http-uwsgi-temp-path=temp/uwsgi_temp \
    --http-scgi-temp-path=temp/scgi_temp

設定項目は以下の通りです。

オプション 意味 
--with-http_ssl_module SSLを使用する
--with-http_random_index_module ページ内の一部をランダムに差し替えるモジュールの使用
--with-http_dav_module WebDAV機能を使用する
--with-http_fastcgi_module fastcgiを使用する(PHPで使う)
--with-pcre=DIR PCREライブラリーのソースディレクトリ(ライブラリ本体ではありません)
--prefix 以降 ディレクトリの設定
$ make
$ porg -lD make install

最後にmake installのところですが、ソースビルドしながらパッケージ管理風にしていくため、porgをかぶせています。

ディレクトリ作成

$ mkdir /opt/nginx/running/temp
$ sudo chown -R nginx:web /opt/nginx/

動作確認

$ /opt/nginx/1.10.2/sbin/nginx -v

pcreのソースディレクトリ設定を抜いて./configureしたとき、
以下のエラーが発生しました。

nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

対処方法として、後からシンボリックリンクを追加する方法もありますが、
なんとなく気持ち悪いので、./configureの時にオプションの指定で対処しましました。
(上記の./configureはやり直した結果のコマンドです。)

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