Openresty Series - Win11 & ( Nginx & Lua & Batch )

在这里插入图片描述
msys2

pacman

/etc/pacman.d/mirrorlist.mingw64
    Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/x86_64

pacman -S mingw-w64-x86_64-toolchain
pacman -S openssl openssl-devel zlib zlib-devel pcre pcre-devel
pacman -S autoconf automake base-devel libtool

Download

/home/unix2linux/openresty-master/openresty-1.27.1.1>
git clone https://gitee.com/mirrors_bungle/ngx_http_proxy_connect_module

/home/unix2linux/openresty-master/openresty-1.27.1.1/objs/lib>
wget https://www.openssl.org/source/openssl-1.1.1w.tar.gz --no-check-certificate
wget https://zlib.net/fossils/zlib-1.3.1.tar.gz
wget http://downloads.sourceforge.net/project/pcre/pcre/8.45/pcre-8.45.tar.gz

/home/unix2linux/openresty-master/openresty-1.27.1.1/objs/lib>lf
openssl-1.1.1w/  pcre-8.45/  zlib-1.3.1/

/home/unix2linux/openresty-master/openresty-1.27.1.1>ls
COPYRIGHT           README.markdown  bundle     ngx_http_proxy_connect_module  patches
README-windows.txt  build            configure  objs

configure

/home/unix2linux/openresty-master/openresty-1.27.1.1>

PCRE=pcre-8.45
ZLIB=zlib-1.3.1
OPENSSL=openssl-1.1.1w
JOBS=12

./configure \
    --with-cc=gcc \
    --prefix=openresty \
    --with-cc-opt='-DFD_SETSIZE=1024' \
    --sbin-path=nginx.exe \
    --with-pcre-jit \
    --without-http_rds_json_module \
    --without-http_rds_csv_module \
    --without-lua_rds_parser \
    --with-ipv6 \
    --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-select_module \
    --with-luajit-xcflags="-DLUAJIT_NUMMODE=2 -DLUAJIT_ENABLE_LUA52COMPAT" \
    --with-pcre=objs/lib/$PCRE \
    --with-zlib=objs/lib/$ZLIB \
    --with-openssl=objs/lib/$OPENSSL \
    --add-module=ngx_http_proxy_connect_module

patch

/home/unix2linux/openresty-master/openresty-1.27.1.1>patch -d build/nginx-1.27.1/ -p 1 < ./ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1015.patch

ngx_http_parse

./build/nginx-1.27.1/src/http/ngx_http_parse.c
    state =sw http_09;  state = swhost http_09;

在这里插入图片描述
Makefile
在这里插入图片描述
make

/home/unix2linux/openresty-master/openresty-1.27.1.1>make
cd /home/unix2linux/openresty-master/openresty-1.27.1.1/build/LuaJIT-2.1-20241104 && make TARGET_STRIP=@: CCDEBUG=-g XCFLAGS='-DLUAJIT_NUMMODE=2 -DLUAJIT_ENABLE_LUA52COMPAT' CC='gcc' PREFIX=openresty/luajit
make[1]: Entering directory '/home/unix2linux/openresty-master/openresty-1.27.1.1/build/LuaJIT-2.1-20241104'
==== Building LuaJIT 2.1 ====
make -C src
make[2]: Entering directory '/home/unix2linux/openresty-master/openresty-1.27.1.1/build/LuaJIT-2.1-20241104/src'
make[2]: Nothing to be done for 'default'.
make[2]: Leaving directory '/home/unix2linux/openresty-master/openresty-1.27.1.1/build/LuaJIT-2.1-20241104/src'
==== Successfully built LuaJIT 2.1 ====
make[1]: Leaving directory '/home/unix2linux/openresty-master/openresty-1.27.1.1/build/LuaJIT-2.1-20241104'
cd /home/unix2linux/openresty-master/openresty-1.27.1.1/build/lua-cjson-2.1.0.14 && make DESTDIR=/home/unix2linux/openresty-master/openresty-1.27.1.1/ LUA_INCLUDE_DIR=/home/unix2linux/openresty-master/openresty-1.27.1.1/build/luajit-root/include/luajit-2.1 LUA_CMODULE_DIR=openresty/lualib LUA_MODULE_DIR=openresty/lualib CJSON_LDFLAGS="-shared -L/home/unix2linux/openresty-master/openresty-1.27.1.1/build/luajit-root -llua51" CJSON_CFLAGS="-g -fpic" CC='gcc'
make[1]: Entering directory '/home/unix2linux/openresty-master/openresty-1.27.1.1/build/lua-cjson-2.1.0.14'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/unix2linux/openresty-master/openresty-1.27.1.1/build/lua-cjson-2.1.0.14'
cd /home/unix2linux/openresty-master/openresty-1.27.1.1/build/lua-redis-parser-0.13 && make DESTDIR=/home/unix2linux/openresty-master/openresty-1.27.1.1/ LUA_INCLUDE_DIR=/home/unix2linux/openresty-master/openresty-1.27.1.1/build/luajit-root/include/luajit-2.1 LUA_LIB_DIR=openresty/lualib LDFLAGS="-shared -L/home/unix2linux/openresty-master/openresty-1.27.1.1/build/luajit-root -llua51" CC='gcc'
make[1]: Entering directory '/home/unix2linux/openresty-master/openresty-1.27.1.1/build/lua-redis-parser-0.13'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/unix2linux/openresty-master/openresty-1.27.1.1/build/lua-redis-parser-0.13'
cd /home/unix2linux/openresty-master/openresty-1.27.1.1/build/nginx-1.27.1 && make
make[1]: Entering directory '/home/unix2linux/openresty-master/openresty-1.27.1.1/build/nginx-1.27.1'
make -f objs/Makefile
.........
tream_lua_input_filters.o \
objs/addon/ngx_http_proxy_connect_module/ngx_http_proxy_connect_module.o \
objs/ngx_modules.o \
-L/home/unix2linux/openresty-master/openresty-1.27.1.1/build/luajit-root -L/home/unix2linux/openresty-master/openresty-1.27.1.1/build/luajit-root -Wl,--export-all-symbols -Wl,-E -Wl,--export-all-symbols -Wl,-E -ladvapi32 -lws2_32 -L/home/unix2linux/openresty-master/openresty-1.27.1.1/build/luajit-root -llua51 -L/home/unix2linux/openresty-master/openresty-1.27.1.1/build/luajit-root -llua51 /home/unix2linux/openresty-master/openresty-1.27.1.1/objs/lib/pcre-8.45/.libs/libpcre.a /home/unix2linux/openresty-master/openresty-1.27.1.1/objs/lib/openssl-1.1.1w/.openssl/lib/libssl.a /home/unix2linux/openresty-master/openresty-1.27.1.1/objs/lib/openssl-1.1.1w/.openssl/lib/libcrypto.a -lgdi32 -lcrypt32 -lws2_32 /home/unix2linux/openresty-master/openresty-1.27.1.1/objs/lib/zlib-1.3.1/libz.a \
-Wl,-E -Wl,--export-all-symbols -Wl,--out-implib=objs/libnginx.a
D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe
: warning: --export-dynamic is not supported for PE+ targets, did you mean --export-all-symbols?
sed -e "s|%%PREFIX%%|openresty|" \
        -e "s|%%PID_PATH%%|openresty/logs/nginx.pid|" \
        -e "s|%%CONF_PATH%%|openresty/conf/nginx.conf|" \
        -e "s|%%ERROR_LOG_PATH%%|openresty/logs/error.log|" \
        < docs/man/nginx.8 > objs/nginx.8
make[2]: Leaving directory '/home/unix2linux/openresty-master/openresty-1.27.1.1/build/nginx-1.27.1'
make[1]: Leaving directory '/home/unix2linux/openresty-master/openresty-1.27.1.1/build/nginx-1.27.1'

make install

/home/unix2linux/openresty-master/openresty-1.27.1.1>make install
cd /home/unix2linux/openresty-master/openresty-1.27.1.1/build/LuaJIT-2.1-20241104 && make TARGET_STRIP=@: CCDEBUG=-g XCFLAGS='-DLUAJIT_NUMMODE=2 -DLUAJIT_ENABLE_LUA52COMPAT' CC='gcc' PREFIX=openresty/luajit
make[1]: Entering directory '/home/unix2linux/openresty-master/openresty-1.27.1.1/build/LuaJIT-2.1-20241104'
==== Building LuaJIT 2.1 ====
make -C src
make[2]: Entering directory '/home/unix2linux/openresty-master/openresty-1.27.1.1/build/LuaJIT-2.1-20241104/src'
make[2]: Nothing to be done for 'default'.
make[2]: Leaving directory '/home/unix2linux/openresty-master/openresty-1.27.1.1/build/LuaJIT-2.1-20241104/src'
==== Successfully built LuaJIT 2.1 ====
......
make[2]: Leaving directory '/home/unix2linux/openresty-master/openresty-1.27.1.1/build/nginx-1.27.1'
make[1]: Leaving directory '/home/unix2linux/openresty-master/openresty-1.27.1.1/build/nginx-1.27.1'
mkdir -p /home/unix2linux/openresty-master/openresty-1.27.1.1/openresty/site/lualib /home/unix2linux/openresty-master/openresty-1.27.1.1/openresty/site/pod /home/unix2linux/openresty-master/openresty-1.27.1.1/openresty/site/manifest

dos

cd D:\msys64\home\unix2linux\openresty-master\openresty-1.27.1.1\openresty
.\luajit -v
.\nginx -v

在这里插入图片描述
nginx.conf

        location /api/com/success {
            content_by_lua_block {
			    ngx.header.content_type = 'text/html; charset=utf-8'
        		local pipe = io.popen("D:\\msys64\\home\\unix2linux\\lua2\\openresty\\html\\bin\\com-success.cmd ")
			    local result = pipe:read("*a")
        		pipe:close()
			    ngx.say(result)
            }
        }
        location /api/com/error {
            content_by_lua_block {
			    ngx.header.content_type = 'text/html; charset=utf-8'
        		local pipe = io.popen("D:\\msys64\\home\\unix2linux\\lua2\\openresty\\html\\bin\\com-error.cmd ")
			    local result = pipe:read("*a")
        		pipe:close()
			    ngx.say(result)
            }
        }

nginx

D:\msys64\home\unix2linux\lua2>start nginx
D:\msys64\home\unix2linux\lua2>nginx -s reload
D:\msys64\home\unix2linux\lua2>nginx -s stop
nginx -s reload

nginx -s stop
nginx -s quit

tasklist /fi "imagename eq nginx.exe"
taskkill /pid 123456 /F

com-success.cmd

:: ---------------------------------------------------------------------------
:: PLEASE DO NOT EDIT THIS FILE
:: ---------------------------------------------------------------------------

@ECHO OFF
@SETLOCAL ENABLEDELAYEDEXPANSION

:: ---------------------------------------------------------------------------

@SET RESULT=0

if %RESULT% EQU 0 (
    @SET TTSS=0123456789ABCDEF0123456789ABCDEF
    @FOR /F %%x IN ('linux_date +"%%s%%N"') DO (
        SET TTSS=%%x
    )

    @ECHO {"code":0,"msg":"success","data":{"token":"!TTSS!"}}
)

com-error.cmd

:: ---------------------------------------------------------------------------
:: PLEASE DO NOT EDIT THIS FILE
:: ---------------------------------------------------------------------------

@ECHO OFF
@SETLOCAL ENABLEDELAYEDEXPANSION

:: ---------------------------------------------------------------------------

@SET RESULT=1

if %RESULT% NEQ 0 (
    @SET TTSS=0123456789ABCDEF0123456789ABCDEF
    @FOR /F %%x IN ('linux_date +"%%s%%N"') DO (
        SET TTSS=%%x
    )

    @ECHO {"code":1,"msg":"error","data":{"token":"!TTSS!"}}
)

在这里插入图片描述
/api/sys/disk
/api/sys/mem
/api/sys/cpu
在这里插入图片描述
在这里插入图片描述
nginx.conf (uri args list)

location /api/args/list {
    content_by_lua_block {
		ngx.header.content_type = 'text/html; charset=utf-8'
        local args = ngx.req.get_uri_args()
        local params = {}
        local result = ''

        result = result .. string.format('{"code":0,"msg":"success","data":[')
        for k, v in pairs(args) do
            params[k] = v
            if not (params[k] == nil) then
                result = result .. string.format('{"%s":"%s"},', k, params[k])
            end
        end
        result = result .. string.format(']}')
        result = string.gsub(result, '},]', '}]')

		ngx.say(result)
    }
}

nginx.conf (uri dynamic args)

location ~* ^/api/args/target/(?<target>.*)$ {
    set $dynamic_api_args_params $target;
    content_by_lua_block {
		ngx.header.content_type = 'text/html; charset=utf-8'
        local params = ngx.var.dynamic_api_args_params;
        local result = ''

        result = result .. string.format('{"code":0,"msg":"success","data":[{"%s":"%s"}]}', 'target', params)

		ngx.say(result)
    }
}

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值