ネットワーク > Webサーバー > NginxをUbuntuにインストール

NginxをUbuntuにインストールする方法のまとめです。
※CentOSにインストールする場合はNginxのページを参照してください。

リンク

参考書

#html{{

table border="0" cellpadding="5"><tr><td valign="top"><a href="https://www.amazon.co.jp/exec/obidos/ASIN/4048702270/vertex9-22/" target="_blank"><img src="http://ecx.images-amazon.com/images/I/51xpswg%2BkkL._SL160_.jpg" border="0"></a></td><td> </td><td valign="top"><a href="https://www.amazon.co.jp/exec/obidos/ASIN/4048702270/vertex9-22/" target="_blank">ハイパフォーマンスHTTPサーバ Nginx入門</a><br>Clement Nedelcu<br>アスキー・メディアワークス<br>2011-04-21<br>¥ 3240</td></tr></table>
}}

Nginxのインストール(Ubuntu編)

自動でインストール

古いバージョンでも良ければ、aptコマンドで自動的にインストールすることも可能。

$ sudo apt install nginx

バージョンの確認

$ nginx -V
nginx version: nginx/1.14.0 (Ubuntu)
built with OpenSSL 1.1.0g  2 Nov 2017
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-FIJPpj/nginx-1.14.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module

Nginxの自動起動

$ sudo /lib/systemd/systemd-sysv-install enable nginx // 有効化
$ sudo /lib/systemd/systemd-sysv-install disable nginx // 無効化

手動でインストール

NginxをUbuntuにソースコードからコンパイルして、手動でインストールする手順のまとめ

ログイン

Ubuntuにログインします。

ダウンロード

Nginx最新安定版(stable)を公式サイトからダウンロードします。

  1. Nginx最新安定版のバージョンを公式サイトで確認します。
    https://nginx.org/en/download.html
    (例) Stable version nginx-1.14.2
  2. ビルド用ディレクトリ(/usr/local/src)に移動します。cf. [Linux] /usr/local/の使い方まとめ · DQNEO起業日記 http://dqn.sakusakutto.jp/2011/08/linux_usrlocal.html
    $ cd /usr/local/src
  3. 圧縮ファイルをダウンロードします。
    $ wget https://nginx.org/download/nginx-1.14.2.tar.gz
    (wgetコマンドがインストールされていない場合は、「$ sudo apt-get install wget」)
  4. ダウンロードしたファイルを解凍します。
    $ tar zxf nginx-1.14.2.tar.gz
  5. カレントディレクトリを移動します。
    $ cd nginx-1.14.2

コンパイル

  1. Nginx用のシステムユーザーを作成します。
    $ sudo adduser --system --no-create-home --shell /bin/false --group --disabled-login nginx
    →リモートログイン及びログインの不可能なシステムユーザnginxを作成
    Adding system user `nginx' (UID 111) ...
    Adding new group `nginx' (GID 116) ...
    Adding new user `nginx' (UID 111) with group `nginx' ...
    Not creating home directory `/home/nginx'.
    のように処理結果が表示された。
  2. gpasswdコマンドで作業者アカウントvagrantをnginxグループに追加します。
    $ gpasswd -a vagrant nginx
    ユーザーvagrantをグループnginxに追加
  3. Nginxに必要なライブラリをインストールします。
    (例では、必須ライブラリの他にHTTPSのコンテンツを処理するOpenSSLライブラリもインストールしています。)
    1. gcc(GNU Compiler Collection)のインストール
      $ sudo apt install build-essential
    2. pcre(Perl Compatible Regular Expressions。Perl5互換の正規表現をC言語で実装したライブラリ)のインストール
      $ sudo apt install libpcre3 libpcre3-dev
    3. zlib(データの圧縮および伸張を行うためのフリーのライブラリ)のインストール
      $ sudo apt install  zlib1g  zlib1g-dev
    4. OpenSSL(暗号化ライブラリ)のインストール。Nginxでは1.1系が必要だがaptコマンドでは1.0系になるので手動でビルドする。最新のバージョンは https://www.openssl.org/source/ で確認すること。
      $ cd /usr/local/src
      $ sudo wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz
      $ sudo tar zxf openssl-1.1.1a.tar.gz
      $ cd openssl-1.1.1a
      $ sudo ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
      $ sudo make
      $ sudo make test
      $ sudo make install
      $ openssl version
      これでNginxをソースからビルドする準備が整いました。
  4. 使用するオプションを付けてconfigureを実行します。
    $ cd /usr/local/src/nginx-1.14.2
    $ sudo ./configure --prefix=/usr/local/nginx-1.14.2 --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module
  5. コンパイルして、インストールします。
    $ sudo make
    $ sudo make test
    $ sudo make install

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2018-12-05 (水) 23:11:19