openresty (nginx + lua),openrestynginxlua


这里部署一个 双层的nginx

 

部署 openresty

    mkdir -p /usr/servers/distribution_nginx

    cd /usr/servers/distribution_nginx

 

上传 openresty 的tar.gz包  下载地址:http://openresty.org/cn/download.html

     tar -zxvf openresty-1.13.6.1.tar.gz

     cd openresty-1.13.6.1/

 

一、安装lua

     cd bundle/LuaJIT-2.1-20171103/

     make clean && make && make install

     如果安装中出现以下错误:

              gcc: Command not found

     解决:

              yum -y install gcc automake autoconf libtool make

         再重新安装lua

 

二、下载ngx_cache_purge模块,该模块用于nginx缓存

         cd /usr/servers/distribution_nginx/openresty-1.13.6.1/bundle

         wget https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz

         tar -xvf 2.3.tar.gz

 

三、下载nginx_upstream_check_module模块,该模块用于ustream健康检查

         wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz

         tar -xvf v0.3.0.tar.gz

 

安装 openresty

         ./configure --prefix=/usr/servers/distribution_nginx/ --with-http_realip_module  --with-pcre  --with-luajit --add-module=./bundle/ngx_cache_purge-2.3/ --add-module=./bundle/nginx_upstream_check_module-0.3.0/ -j2

 

         会报错,根据错误提示,安装以下的库

         yum install gcc

         yum install -y pcre pcre-devel

         yum install -y openssl openssl-devel

         yum install -y zlib zlib-devel (如果安装过,就不用安装)

      

         执行成功过后执行

         make && make install

         

检查安装是否成功

         cd /usr/servers/distribution_nginx/nginx/sbin

          ./nginx -v 查看版本

          ./nginx 启动

           出现以下内容:

              ps -ef| grep nginx

              root 14827 1 0 14:07 ? 00:00:00 nginx: master process ./nginx
              nobody 14828 14827 0 14:07 ? 00:00:00 nginx: worker process

 

 

--------------------------------------------------------------------------------------------------------------------------------------------------------------

nginx + lua的 hello world

    

   cd  /usr/servers/distribution_nginx/nginx/

 

   cd  conf

   vi  lua.conf

   添加如下内容

          server {
              listen 80; 
              server_name _; 

              location /lua { 
                 default_type 'text/html'; 
                 content_by_lua 'ngx.say("hello world"); 
              } 
        }

 

    vi nginx.conf

    在http 部分添加:

 

     http {

        lua_package_path "/usr/servers/lualib/?.lua;;";
        lua_package_cpath "/usr/servers/lualib/?.so;;";

        include lua.conf;


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

          .

          .

          .

 

    验证配置是否正确:

         cd ../sbin

          ./nginx -t 

           看到

              nginx: the configuration file /usr/servers/distribution_nginx//nginx/conf/nginx.conf syntax is ok
              nginx: configuration file /usr/servers/distribution_nginx//nginx/conf/nginx.conf test is successful

 

    重新加载

         ./nginx -s reload

相关内容

    暂无相关文章