LoginSignup
0
0

More than 5 years have passed since last update.

nginxをvagrantの仮想環境にinstallする方法

Last updated at Posted at 2016-06-16

nginxをvagrantの仮想環境にinstallする方法と参考URLをまとめます。

事前環境

CentOS6.4
Vagrant

nginxのダウンロード

nginxを公式サイトからダウンロードいたします。
Mainline版とStable版がありますが、通常は最新のMainlineが推奨されているのでMainlineをダウンロードしましょう!
ダウンロードURL

nginxをvagrantの環境へアップロードする

scpでvagrantの仮想環境上にダウンロードしたtar.gzファイルをアップロードしました。
以下、ターミナル上での作業です。(windowsであればコマンドプロンプト)

$ scp nginx-1.11.1.tar.gz root@192.168.33.10:/var/tmp   
root@192.168.33.10's password: 
nginx-1.11.1.tar.gz                           100%  892KB 892.0KB/s   00:00    

これで仮想環境の/var/tmpファイル以下にnginxのインストールファイルがアップロードされました。

nginxのインストールコマンド

0. cd /var/tmp
1. tar xvf nginx-1.11.1.tar.gz 
2. cd nginx-1.11.1
3. ./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx
5. make
6. sudo make install
7. export PATH=/usr/local/nginx/sbin:$PATH

ぶつかったところ

不足ライブラリのインストール

3のコマンドにて必用なライブラリがないと怒られたので都度入れていきました。

[vagrant@vagrant-centos64 nginx-1.11.1]$ ./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx
...
./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(正規表現処理のライブラリ)がなかったからインストールしました。

// PCREがyumのパッケージにないか調べる
[vagrant@vagrant-centos64 nginx-1.11.1]$ yum search pcre
pcre-devel.i686 : Development files for pcre
pcre-devel.x86_64 : Development files for pcre
pcre-static.x86_64 : Static library for pcre
pcre2-devel.i686 : Development files for pcre2
pcre2-devel.x86_64 : Development files for pcre2
pcre2-static.i686 : Static library for pcre2
pcre2-static.x86_64 : Static library for pcre2
pcre2-tools.x86_64 : Auxiliary utilities for pcre2
ghc-pcre-light.x86_64 : Perl5 compatible regular expressions library
ghc-pcre-light-devel.x86_64 : Perl5 compatible regular expressions library
                            : development files
opensips-regex.x86_64 : RegExp via PCRE library
pcre.x86_64 : Perl-compatible regular expression library
pcre.i686 : Perl-compatible regular expression library
pcre2.i686 : Perl-compatible regular expression library
pcre2.x86_64 : Perl-compatible regular expression library

[vagrant@vagrant-centos64 nginx-1.11.1]$ sudo yum install pcre pcre-devel
Complete!

zlibインストール

gzip圧縮等のライブラリのzlibもなかったようなのでインストール

[vagrant@vagrant-centos64 tmp]cd .. // var/tmpへ移動
[vagrant@vagrant-centos64 tmp]$ wget http://www.zlib.net/zlib-1.2.8.tar.gz
[vagrant@vagrant-centos64 tmp]$ tar xvf zlib-1.2.8.tar.gz 
[vagrant@vagrant-centos64 tmp]$ cd zlib-1.2.8/
[vagrant@vagrant-centos64 zlib-1.2.8]$ make clean 
[root@vagrant-centos64 zlib-1.2.8]# ./configure -shared -libdir=/lib
[root@vagrant-centos64 zlib-1.2.8]# make
[root@vagrant-centos64 zlib-1.2.8]# make install

install完了

install完了しました!

[root@vagrant-centos64 nginx-1.11.1]# nginx -V
nginx version: nginx/1.11.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) 
configure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx

起動〜停止

せっかくinstallできたので起動〜停止まで

起動

[root@vagrant-centos64 nginx-1.11.1]# sudo nginx

オプション付き起動

[root@vagrant-centos64 nginx-1.11.1]# sudo nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

-t で設定ファイルの文法チェックを行ってくれます。

起動確認

プロセスを見てみます。

[root@vagrant-centos64 nginx-1.11.1]# ps ax | grep nginx
17623 ?        Ss     0:00 nginx: master process nginx
17624 ?        S      0:00 nginx: worker process
17632 pts/0    S+     0:00 grep nginx

masterプロセス・workerプロセスが動いてます。

ポートも80をbindできてます

[root@vagrant-centos64 nginx-1.11.1]# ss -an | grep LISTEN | grep :80
LISTEN     0      128                       *:80  

参考

zlibのinstall
http://lifeworker.jp/wordpress/how-to-zlib-install.html
nginx実践入門
https://www.amazon.co.jp/nginx%E5%AE%9F%E8%B7%B5%E5%85%A5%E9%96%80-WEB-DB-PRESS-plus/dp/4774178667

Install Nginx on Ubuntu

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