nginx+lua+redis

技術文書
2015/05/19

nginxプロキシ

[admin@49.212.176.26 ~]$ su
[root@49.212.176.26 ~]$ rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
[root@49.212.176.26 ~]$ yum install nginx
[root@49.212.176.26 ~]$ mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/node-app.conf
[root@49.212.176.26 ~]$ vi /etc/nginx/conf.d/node-app.conf
server {
    listen       8000;
    server_name  localhost;
    proxy_redirect                          off;
    proxy_set_header Host                   $host;
    proxy_set_header X-Real-IP              $remote_addr;
    proxy_set_header X-Forwarded-Host       $host;
    proxy_set_header X-Forwarded-Server     $host;
    proxy_set_header X-Forwarded-For        $proxy_add_x_forwarded_for;

    location / {
        proxy_pass http://localhost:3000/;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
[root@49.212.176.26 ~]$  chkconfig nginx on

オープンファイルリミット設定

[root@49.212.176.26 ~]$ulimit -n
1024
[root@49.212.176.26 ~]$vi /etc/sysconfig/init
ulimit -n 65536
[root@49.212.176.26 ~]$reboot
[root@49.212.176.26 ~]$ulimit -n
65536

nginx + lua + redis

ソースインストールする場合
http://wiki.nginx.org/HttpRedis2Module

openrestyを利用する場合
http://openresty.org/
https://github.com/openresty/lua-resty-redis

今回はより簡単にインストールできるopenrestyを採用

[]# cd /usr/local/src/
[]# curl -O

nginx設定
[]# vi /usr/local/openresty/nginx/conf/nginx.conf

nginx起動
[]# /usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf

参考URL
http://qiita.com/kz_takatsu/items/e94805a8e3cc285f9b33

lua-resty-template

[]# cd /usr/local/src
[]# git clone https://github.com/bungle/lua-resty-template
[]# cp lua-resty-template/lib/resty/template.lua /usr/local/openresty/lualib/resty/
[]# nginx -s reload

ファイル