LoginSignup
6
6

More than 5 years have passed since last update.

Mac OS X (10.8) での nginx + lua-nginx-module インストール

Posted at

nginx + lua-nginx-module の環境構築

nginx + lua-nginx-module を利用してなんかやりたいけど、
わざわざUbuntuの入ったVMを〜とかはだるかったので、Mac OS X (10.8)で
環境構築をしてみた。

Mac OS Xでの環境構築

pcre、LuaJITはnginxのインストールで必要なので、
homebrewでインストールしておく。
Luaでも問題ないのだけど、今回はLuaJITで。

brew install pcre
brew install luajit

nginx + lua-nginx-moduleのインストール

手順を公式で確認すると、
を見ると、nginx_devel_kit、ngx_luaが必要とのこと。
nginxについては先日(2013-04-24)リリースされたnginx1.4.0を利用する。

git clone したり、 git checkout したり。

> mkdir -p /usr/local/sandbox/nginx_lua_module
> cd /usr/local/sandbox/nginx_lua_module
>
> git clone git://github.com/simpl/ngx_devel_kit.git
> git clone git://github.com/chaoslawful/lua-nginx-module.git
> curl -O http://nginx.org/download/nginx-1.4.0.tar.gz
>
> tar -xvzf nginx-1.4.0.tar.gz
>
> cd ngx_devel_kit
> git checkout -b v0.2.18 v0.2.18
> cd ../lua-nginx-module
> git checkout -b v0.8.1 v0.8.1
> cd ../nginx-1.4.0

LuaJITのライブラリ及びヘッダファイルパスを設定

> export LUAJIT_LIB="`brew --cellar luajit`/2.0.1/lib"
> export LUAJIT_INC="`brew --cellar luajit`/2.0.1/include/luajit-2.0"

nginxのビルド準備

pcreはhomebrewを利用してインストールしているので、
CFLAGS及びライブラリへのリンクを指定する。

> mkdir -p /usr/local/nginx-1.4.0
> ./configure --prefix=/usr/local/nginx-1.4.0 \
> --add-module=/usr/local/sandbox/nginx_lua_module/ngx_devel_kit \
> --add-module=/usr/local/sandbox/nginx_lua_module/lua-nginx-module \
> --with-cc-opt='-O0 -I/usr/local/Cellar/pcre/8.32/include' \
> --with-ld-opt='-L/usr/local/Cellar/pcre/8.32/lib' 

configureスクリプトが通ったらビルド。

> make -j2
> make install

起動テスト

ビルドが通り、インストールも終わったら起動テストを行なってみる。

sudo /usr/local/nginx-1.4.0/sbin/nginx

http://localhost/ にアクセス。

nginx startup

OK。

lua-nginx-moduleの動作確認

既存のnginx.confに最低限の設定だけ残したり、編集したりして動作確認する。

> cd /usr/local/nginx-1.4.0/conf
> vi nginx.conf
worker_processes  1;

error_log  logs/error.log;
pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    access_log  logs/access.log;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        access_log  logs/host.access.log;

        location / {
            root   html;
            index  index.html index.htm;
        }

        location /lua-test {
            default_type 'text/plain';
            content_by_lua "ngx.say('Hello,world!')";
        }
    }
}

新たに追加した/lua-testに対しアクセスをしてみる。

lua-test

動作確認OK。
これで遊べるようになった。

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