创建项目文件基于Openresty框架和lua脚本进行处理

This commit is contained in:
wanglei 2025-09-25 13:56:33 +08:00
commit 280c6e5cdf
7 changed files with 130 additions and 0 deletions

11
AuthPlatform.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="LUA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="Lua" jdkType="Lua SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,3 @@
@echo off
call openresty-stop.bat
call openresty-start.bat

40
bat/openresty-start.bat Normal file
View File

@ -0,0 +1,40 @@
@echo off
rem 启动标志 flag=0 表示之前已经启动 flag=1 表示现在立即启动
set flag=0
rem 设置 openresty/nginx的安装目录
set installPath=D:\work\OpenResty\openresty-1.27.1.2-win64
rem 设置 Nginx 项目的工作目录
set projectPath=D:\OpenrestyPro\AuthService
rem 设置 项目的配置文件
set PROJECT_CONF=nginx.conf
echo installPath: %installPath%
echo project prefix path: %projectPath%
echo config file: %projectPath%/conf/%PROJECT_CONF%
echo openresty starting.....
rem 查找openresty/nginx进程信息然后设置flag标志位
tasklist|find /i "nginx.exe" > nul
if %errorlevel%==0 (
echo "openresty/nginx already running ! "
rem exit /b
) else set flag=1
rem 如果需要,则启动 openresty/nginx
rem -p指定前缀路径-c指定nginx配置文件
if %flag%==1 (
start nginx.exe -p "%projectPath%" -c "%projectPath%/conf/%PROJECT_CONF%"
ping localhost -n 2 > nul
)
rem 输出openresty/nginx的进程信息
tasklist /fi "imagename eq nginx.exe"
tasklist|find /i "nginx.exe" > nul
if %errorlevel%==0 (
echo "openresty/nginx starting succeced!"
)

7
bat/openresty-status.bat Normal file
View File

@ -0,0 +1,7 @@
@echo off
tasklist|find /i "nginx.exe" > nul
if %errorlevel%==0 (
tasklist /fi "imagename eq nginx.exe"
echo "openresty/nginx is running!"
exit /b
) else echo "openresty/nginx is stoped!"

6
bat/openresty-stop.bat Normal file
View File

@ -0,0 +1,6 @@
@echo off
tasklist|find /i "nginx.exe" > nul
if %errorlevel%==0 (
taskkill /f /t /im nginx.exe > nul
echo "openresty/nginx stoped!"
)else echo "openresty/nginx not running!"

62
conf/nginx.conf Normal file
View File

@ -0,0 +1,62 @@
worker_processes 2;
error_log logs/error.log info;
events {
worker_connections 1024;
}
http {
default_type application/octet-stream;
access_log logs/access.log;
lua_package_path 'src/share/?.lua;;'; #lua 模块
lua_package_cpath "src/share/lib/?.so;;"; #c模块
##include lua.conf; #导入自定义lua配置文件
##resolver 8.8.8.8;
lua_shared_dict share_mem_cache 10m; ##共享内存大小
lua_shared_dict routes_cache 10m; ##路由内存大小
server {
listen 9090;
server_name localhost;
default_type text/html;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location /api {
content_by_lua_file src/api/api.lua;
}
#location ^~ /api/ {
# rewrite_by_lua_block {
# local uri = ngx.var.uri
# if string.match(uri, "^/api/v1/") then
# ngx.req.set_uri("/api_v1")
# elseif string.match(uri, "^/api/v2/") then
# ngx.req.set_uri("/api_v2")
# end
# }
#}
#location /api_v1 {
# content_by_lua_file conf/lua/api_v1.lua;
#}
#location /api_v2 {
# content_by_lua_file conf/lua/api_v2.lua;
#}
# 动态路由处理
#location /router {
# access_by_lua_file "src/routes/dynamic_router.lua";
# proxy_pass $target;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
#}
# 路由更新接口
#location /update-routes {
# content_by_lua_file "src/routes/route_updater.lua";
#}
}
}

1
logs/nginx.pid Normal file
View File

@ -0,0 +1 @@
12764