lua openresty执行lua命令


lua openresty执行lua命令

           

openresty 官网:http://openresty.org/cn/

lua_ngx_module:https://github.com/openresty/lua-nginx-module

        

                

                                

openresty

       

openresty在nginx的基础上,整合了三方模块,可以直接使用

# openresty 默认安装的模块
root@7bd203df440c:/usr/local/openresty/nginx# ./sbin/nginx -V
nginx version: openresty/1.19.9.1
built with OpenSSL 1.1.1l  24 Aug 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx \
--with-cc-opt='-O2 -DNGX_LUA_ABORT_AT_PANIC -I/usr/local/openresty/zlib/include -I/usr/local/openresty/pcre/include -I/usr/local/openresty/openssl111/include'  \

--add-module=../ngx_devel_kit-0.3.1 \
--add-module=../echo-nginx-module-0.62 \
--add-module=../xss-nginx-module-0.06 \
--add-module=../ngx_coolkit-0.2 \
--add-module=../set-misc-nginx-module-0.32 \
--add-module=../form-input-nginx-module-0.12 \
--add-module=../encrypted-session-nginx-module-0.08 \
--add-module=../srcache-nginx-module-0.32 \
--add-module=../ngx_lua-0.10.20 \
--add-module=../ngx_lua_upstream-0.07 \
--add-module=../headers-more-nginx-module-0.33 \
--add-module=../array-var-nginx-module-0.05 \
--add-module=../memc-nginx-module-0.19 \
--add-module=../redis2-nginx-module-0.15 \
--add-module=../redis-nginx-module-0.3.7 \
--add-module=../ngx_stream_lua-0.0.10 \

--with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib -L/usr/local/openresty/zlib/lib -L/usr/local/openresty/pcre/lib -L/usr/local/openresty/openssl111/lib -Wl,-rpath,/usr/local/openresty/zlib/lib:/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl111/lib' \

--with-pcre-jit --with-stream \
--with-stream_ssl_module --with-stream_ssl_preread_module \
--with-http_v2_module --without-mail_pop3_module \
--without-mail_imap_module --without-mail_smtp_module \
--with-http_stub_status_module --with-http_realip_module \
--with-http_addition_module --with-http_auth_request_module \
--with-http_secure_link_module --with-http_random_index_module \
--with-http_gzip_static_module --with-http_sub_module \
--with-http_dav_module --with-http_flv_module \
--with-http_mp4_module --with-http_gunzip_module \
--with-threads --with-stream --with-http_ssl_module

         

下载镜像

docker pull openresty/openresty

          

配置文件位置

huli@hudeMacBook-Pro conf % docker exec -it openresty bash
# 工作目录
root@7bd203df440c:/# cd /usr/local/openresty
root@7bd203df440c:/usr/local/openresty# ls 
bin  luajit  lualib  nginx  openssl111	pcre  site  zlib

# nginx目录
root@7bd203df440c:/usr/local/openresty# cd nginx
root@7bd203df440c:/usr/local/openresty/nginx# ls
conf  html  logs  sbin

# nginx配置目录
root@7bd203df440c:/usr/local/openresty/nginx# ls conf
fastcgi.conf		koi-win		    scgi_params
fastcgi.conf.default	mime.types	    scgi_params.default
fastcgi_params		mime.types.default  uwsgi_params
fastcgi_params.default	nginx.conf	    uwsgi_params.default
koi-utf			nginx.conf.default  win-utf

          

nginx.conf

root@7bd203df440c:/usr/local/openresty/nginx/conf# cat nginx.conf
# nginx.conf  --  docker-openresty
#
# This file is installed to:
#   `/usr/local/openresty/nginx/conf/nginx.conf`
# and is the file loaded by nginx at startup,
# unless the user specifies otherwise.
#
# It tracks the upstream OpenResty's `nginx.conf`, but removes the `server`
# section and adds this directive:
#     `include /etc/nginx/conf.d/*.conf;`
#
# The `docker-openresty` file `nginx.vh.default.conf` is copied to
# `/etc/nginx/conf.d/default.conf`.  It contains the `server section
# of the upstream `nginx.conf`.
#
# See https://github.com/openresty/docker-openresty/blob/master/README.md#nginx-config-files
#

#user  nobody;
#worker_processes 1;

# Enables the use of JIT for regular expressions to speed-up their processing.
pcre_jit on;



#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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

    # Enables or disables the use of underscores in client request header fields.
    # When the use of underscores is disabled, request header fields whose names contain underscores are marked as invalid and become subject to the ignore_invalid_headers directive.
    # underscores_in_headers off;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

        # Log in JSON Format
        # log_format nginxlog_json escape=json '{ "timestamp": "$time_iso8601", '
        # '"remote_addr": "$remote_addr", '
        #  '"body_bytes_sent": $body_bytes_sent, '
        #  '"request_time": $request_time, '
        #  '"response_status": $status, '
        #  '"request": "$request", '
        #  '"request_method": "$request_method", '
        #  '"host": "$host",'
        #  '"upstream_addr": "$upstream_addr",'
        #  '"http_x_forwarded_for": "$http_x_forwarded_for",'
        #  '"http_referrer": "$http_referer", '
        #  '"http_user_agent": "$http_user_agent", '
        #  '"http_version": "$server_protocol", '
        #  '"nginx_access": true }';
        # access_log /dev/stdout nginxlog_json;

    # See Move default writable paths to a dedicated directory (#119)
    # https://github.com/openresty/docker-openresty/issues/119
    client_body_temp_path /var/run/openresty/nginx-client-body;
    proxy_temp_path       /var/run/openresty/nginx-proxy;
    fastcgi_temp_path     /var/run/openresty/nginx-fastcgi;
    uwsgi_temp_path       /var/run/openresty/nginx-uwsgi;
    scgi_temp_path        /var/run/openresty/nginx-scgi;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;

    # Don't reveal OpenResty version to clients.
    # server_tokens off;
}

         

/etc/nginx/conf.d/default.conf

root@7bd203df440c:/usr/local/openresty/nginx/conf# ls /etc/nginx/conf.d        
default.conf
root@7bd203df440c:/usr/local/openresty/nginx/conf# cat /etc/nginx/conf.d/default.conf
# nginx.vh.default.conf  --  docker-openresty
#
# This file is installed to:
#   `/etc/nginx/conf.d/default.conf`
#
# It tracks the `server` section of the upstream OpenResty's `nginx.conf`.
#
# This config (and any other configs in `etc/nginx/conf.d/`) is loaded by
# default by the `include` directive in `/usr/local/openresty/nginx/conf/nginx.conf`.
#
# See https://github.com/openresty/docker-openresty/blob/master/README.md#nginx-config-files
#


server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/local/openresty/nginx/html;
        index  index.html index.htm;
    }

    location /lua {
        default_type "applictaion/json";
        content_by_lua "ngx.say('hello gtlx')";
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/local/openresty/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           /usr/local/openresty/nginx/html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

           

              

                                

使用示例

       

default.conf

server {
    listen       80;
    server_name  localhost;

    location / {
        root   /usr/local/openresty/nginx/html;
        index  index.html index.htm;
    }

    location /lua {
        default_type "applictaion/json";
        content_by_lua "ngx.say('hello gtlx')";
    }  # 使用lua_ngx_module输出内容

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/local/openresty/nginx/html;
    }

}

       

创建容器

docker run -it -d -p 8080:80 \
-v /Users/huli/lua/openresty/conf/default.conf:/etc/nginx/conf.d/default.conf \
--name openresty openresty/openresty

                       

使用测试

huli@hudeMacBook-Pro conf % curl localhost:8080/lua
hello gtlx

       

             

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值