修改配置文件,修改接口并增加文件将接口放到配置中
This commit is contained in:
parent
e9ec555a24
commit
94ebf0a452
133
conf/nginx.conf
133
conf/nginx.conf
|
|
@ -7,9 +7,10 @@ events {
|
|||
}
|
||||
|
||||
http {
|
||||
lua_package_path 'src/?/?.lua;src/?.lua;src/share/?/?.lua;src/share/?.lua;/home/frankly/work/AuthPlatform/src/share/lib/?/?.lub;/home/frankly/work/AuthPlatform/src/share/lib/ngx-oauth/?.lua;/home/frankly/work/AuthPlatform/src/share/?/?.lub;/home/frankly/work/AuthPlatform/src/share/?.lua;;';
|
||||
lua_package_cpath 'src/share/lib/?.so;;';
|
||||
lua_package_path '$profix/src/?/?.lua;$profix/src/?.lua;;';
|
||||
lua_package_cpath '$profix/src/share/lib/?.so;;';
|
||||
|
||||
include system/user.conf
|
||||
# Path of the file with trusted CA certificates.
|
||||
#lua_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
|
||||
|
||||
|
|
@ -24,133 +25,5 @@ http {
|
|||
log_not_found off;
|
||||
access_log off;
|
||||
}
|
||||
|
||||
#API接口文件
|
||||
location /api {
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/api.lua';
|
||||
}
|
||||
|
||||
#测试相关插件接口
|
||||
location /testTree {
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testRadixtree.lua';
|
||||
}
|
||||
location /testSQL {
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testPostgres.lua';
|
||||
}
|
||||
location /testRedis {
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testRedis.lua';
|
||||
}
|
||||
location /testObj {
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testObjClass.lua';
|
||||
}
|
||||
location /testWsdl {
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testWebService.lua';
|
||||
}
|
||||
location /wsdl {
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testWsdl.lua';
|
||||
}
|
||||
location /jsonSchema {
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testJsonSchema.lua';
|
||||
}
|
||||
location /testOrm {
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testOrm.lua';
|
||||
}
|
||||
location /checkip {
|
||||
content_by_lua_block {
|
||||
local ipmatcher = require("resty.ipmatcher")
|
||||
local client_ip = ngx.var.remote_addr
|
||||
ngx.say(ipmatcher.new({"127.0.0.1", "192.168.0.11/16"}).match(client_ip))
|
||||
}
|
||||
}
|
||||
|
||||
location /t {
|
||||
rewrite_by_lua_block {
|
||||
|
||||
local aes = require "resty.aes"
|
||||
local str = require "resty.string"
|
||||
local cjson = require('cjson')
|
||||
local key = "aaaaaaaaaaaaaaaa"
|
||||
local text = "7614463 1574189821 175.168.224.225"
|
||||
local length = 16
|
||||
local count = string.len(text)
|
||||
local add = length - (count % length)
|
||||
local tail_str='\0'
|
||||
for i=1,add-1 do
|
||||
tail_str=tail_str .. '\0'
|
||||
end
|
||||
text = text .. tail_str
|
||||
ngx.say(text)
|
||||
-- 创建 AES 对象
|
||||
local aes_128_cbc = aes:new(key, nil, aes.cipher(128, "cbc"), {iv=key})
|
||||
-- 加密数据
|
||||
local encrypted, err = aes_128_cbc:encrypt(text)
|
||||
if not encrypted then
|
||||
ngx.log(ngx.ERR, "Failed to encrypt: ", err)
|
||||
return ngx.exit(500)
|
||||
end
|
||||
ngx.say(str.to_hex(encrypted))
|
||||
|
||||
local crc_32s, crc_32l
|
||||
crc_32s = ngx.crc32_short(str)
|
||||
crc_32l = ngx.crc32_long(str)
|
||||
--local hmac = ngx.hmac_sha1(key, str)
|
||||
local md5 = ngx.md5(str)
|
||||
local md5_bin = ngx.md5_bin(str)
|
||||
local sha1_bin = ngx.sha1_bin(str)
|
||||
ngx.say("crc_32_short: ", crc_32s, ", crc_32_long: ", crc_32l)
|
||||
ngx.say("hmac: ", ngx.encode_base64(hmac))
|
||||
ngx.say("md5: ", md5, ", md5_bin: ", ngx.encode_base64(md5_bin))
|
||||
ngx.say("sha1_bin: ", ngx.encode_base64(sha1_bin))
|
||||
|
||||
-- 将加密后的数据转换为十六进制字符串以便于查看或传输
|
||||
local encrypted_hex = cjson.encode({iv = ngx.encode_base64(iv), ciphertext = ngx.encode_base64(encrypted)})
|
||||
ngx.say("Encrypted: ", encrypted_hex)
|
||||
}
|
||||
}
|
||||
}
|
||||
server {
|
||||
listen 1443 ssl; #修改端口443
|
||||
server_name 127.0.0.1;
|
||||
|
||||
set $oauth_client_id '01234567-89ab-cdef-0123-456789abcdef';
|
||||
set $oauth_client_secret 'very-top-secret-password';
|
||||
set $oauth_redirect_uri '/_oauth/callback';
|
||||
set $oauth_oaas_uri 'https://127.0.0.1/oauth';
|
||||
|
||||
ssl_certificate /home/frankly/work/server.crt;
|
||||
ssl_certificate_key /home/frankly/work/server.key;
|
||||
|
||||
ssl_session_cache shared:SSL:1m;
|
||||
ssl_session_timeout 5m;
|
||||
|
||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #֧支持TLS协议
|
||||
|
||||
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; #支持的加密算法
|
||||
ssl_prefer_server_ciphers on;
|
||||
|
||||
location /_oauth/login {
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/share/lib/ngx-oauth-login.lua';
|
||||
}
|
||||
|
||||
location /_oauth/callback {
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/share/lib/ngx-oauth-redirect-handler.lua';
|
||||
}
|
||||
|
||||
location /_oauth/logout {
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/share/lib/ngx-oauth-logout.lua';
|
||||
}
|
||||
|
||||
location /_proxy {
|
||||
access_by_lua_file '/home/frankly/work/AuthPlatform/src/share/lib/ngx-oauth-proxy.lua';
|
||||
|
||||
rewrite ^/_proxy/(.*)$ /$1 break;
|
||||
##proxy_pass https://resource-provider;
|
||||
}
|
||||
|
||||
# 错误页处理
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root html;
|
||||
}
|
||||
}
|
||||
}
|
||||
4
conf/system/user.conf
Normal file
4
conf/system/user.conf
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#API接口文件
|
||||
location /api {
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/api.lua';
|
||||
}
|
||||
|
|
@ -3,19 +3,18 @@
|
|||
--- Created by admin.
|
||||
--- DateTime: 2025/9/24 15:29
|
||||
---
|
||||
local radix = require("resty.radixtree")
|
||||
|
||||
local function say_hello(req)
|
||||
ngx.say("Hello, World!")
|
||||
end
|
||||
|
||||
local function get_user(req)
|
||||
ngx.say("call get_user")
|
||||
local user_id = req.args.id or "unknown"
|
||||
ngx.say("User ID: " .. user_id)
|
||||
end
|
||||
|
||||
local function get_id(req)
|
||||
ngx.say("call get_id")
|
||||
local args = req.get_uri_args()
|
||||
-- 获取单个参数
|
||||
local id = args["id"] -- 值为 "john"
|
||||
|
|
@ -37,14 +36,33 @@ local function test(req)
|
|||
end
|
||||
|
||||
local routes = {
|
||||
["/hello"] = say_hello,
|
||||
["/user"] = get_user,
|
||||
["/userid"] = get_id,
|
||||
{
|
||||
paths = { "/login/*action" },
|
||||
metadata = { "metadata /login/action" },
|
||||
methods = { "GET", "POST", "PUT" },
|
||||
remote_addrs = { "127.0.0.1", "192.168.0.0/16", "::1", "fe80::/32" }
|
||||
},
|
||||
{
|
||||
paths = { "/user/:name" },
|
||||
metadata = { "metadata /user/name" },
|
||||
methods = { "GET" },
|
||||
},
|
||||
{
|
||||
paths = { "/admin/:name", "/superuser/:name" },
|
||||
metadata = { "metadata /admin/name" },
|
||||
methods = { "GET", "POST", "PUT" },
|
||||
filter_fun = function(vars, opts)
|
||||
return vars["arg_access"] == "admin"
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
local function handle_request()
|
||||
--获取接口请求的方法
|
||||
local request_method = ngx.var.request_method
|
||||
local args = nil
|
||||
ngx.say(request_method)
|
||||
|
||||
local args = ngx.var.get_uri_args
|
||||
ngx.say(request_method)
|
||||
|
||||
local uri = ngx.var.request_uri
|
||||
|
|
|
|||
|
|
@ -16,19 +16,5 @@ conn:connect(function(err)
|
|||
print("Error connecting to database: ", err)
|
||||
else
|
||||
print("Connected to the PostgreSQL server.")
|
||||
|
||||
-- 执行一个简单的查询
|
||||
conn:query("SELECT version()")
|
||||
:on_data(function(row)
|
||||
print("Database Version: ", row[1])
|
||||
end)
|
||||
:on_error(function(err)
|
||||
print("Query Error: ", err)
|
||||
end)
|
||||
:on_finish(function()
|
||||
print("Query finished.")
|
||||
-- 关闭连接
|
||||
conn:close()
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
|
@ -19,7 +19,7 @@ return {
|
|||
HOST = "127.0.0.1", -- postgres host
|
||||
PORT = 5432, -- postgres port
|
||||
USERNAME = "postgres",
|
||||
PASSWORD = "123456", -- postgres password
|
||||
PASSWORD = "1qaz2wsx", -- postgres password
|
||||
DATABASE = "postgres"
|
||||
}
|
||||
}
|
||||
|
|
@ -17,18 +17,3 @@ conn:connect(function(err)
|
|||
print("Connected to the PostgreSQL server.")
|
||||
end
|
||||
end)
|
||||
|
||||
-- 执行一个简单的查询
|
||||
|
||||
conn:query("SELECT version()")
|
||||
:on_data(function(row)
|
||||
print("Database Version: ", row[1])
|
||||
end)
|
||||
:on_error(function(err)
|
||||
print("Query Error: ", err)
|
||||
end)
|
||||
:on_finish(function()
|
||||
print("Query finished.")
|
||||
-- 关闭连接
|
||||
conn:close()
|
||||
end)
|
||||
5
src/test/test.lua
Normal file
5
src/test/test.lua
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
||||
--- Created by admin.
|
||||
--- DateTime: 2025/10/15 09:12
|
||||
---
|
||||
Loading…
Reference in New Issue
Block a user