LoginSignup
7
7

More than 5 years have passed since last update.

誰でも動かせるNginx

Last updated at Posted at 2015-05-21

実行環境

CentOS 6.5
Nginx 1.9.0
※rpmだとモジュール追加が出来ないため、ソースからインストールしています

ユーザー作成

まずはnginx実行ユーザ作成しておきます。


# useradd --shell /sbin/nologin nginx

必要ライブラリインストール

事前にnginxに必要なライブラリインストールしておきます。
※きっとHTTPSやってみたいってなると思いそれ関連も入れてます。


# yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

ダウンロードnginx

最新の1.9.0をパッケージダウンロードします。
ダウンロード先は今回は/usr/local/src/sourceとしておきます。


# cd /usr/local/src/source/
# wget http://nginx.org/download/nginx-1.9.0.tar.gz

展開とインストール

ダウンロード先に移動し、configureで追加モジュール指定しインストールします。


# tar xvfz nginx-1.9.0.tar.gz
# cd /usr/local/src/source/nginx-1.9.0/
# ./configure --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module
# make
# make install

起動スクリプト

公開されてるのを利用します。以下のURLのものをコピーし、/etc/init.d/nginxファイルを作成し貼り付けます。


# touch /etc/init.d/nginx

vi で開いてコピペ

これを参考に必要なパスだけ変えます。今回はバイナリが/usr/localにインストールされている状況とします。


nginx="/usr/local/nginx/sbin/nginx" 
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

コンフィグテスト

リスタートや起動前にコンフィグチェック可能です。以下コマンドでチェックします。
以下のようにokやsuccessfulが出ていれば問題ありません。


# /usr/local/nginx/sbin/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

起動

以下コマンドで起動出来ます。停止はstop、コンフィグ再読込はreloadです。


# /etc/init.d/nginx start
Starting nginx:                                            [  OK  ]

起動後ブラウザで以下のようにでればOK

クリップボード02.png

モジュール追加したい

モジュールはたくさんあり動的に追加はできません。rpmで入れてしまうと追加ができません。
試しに接続状態を確認できるstub_status_moduleを入れてみましょう

現在のモジュール状況は以下で確認できます。バージョンの確認も出来てますね。


# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.9.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module 

--with-http_stub_status_moduleを付けてconfigureし直しstub_status_module追加します。そして再度インストールします。


# ./configure --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_stub_status_module

# make;make install

再度nginx -Vコマンドを実行しモジュール確認します。
--with-http_stub_status_moduleが入ってることが見えますね。


# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.9.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_stub_status_module

reloadでコンフィグ再読込させ、追加モジュールを有効にします。


# /etc/init.d/nginx reload

以下のようにブラウザからhttp://IPアドレス/nginx_statusで接続状況が見えてますね^^

クリップボード01.png

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