diff --git a/prod/conf.d/music-room.conf b/prod/conf.d/music-room.conf new file mode 100644 index 0000000..505485b --- /dev/null +++ b/prod/conf.d/music-room.conf @@ -0,0 +1,52 @@ +server { + server_name music-room.alchemy-studio.cn; + listen 443 ssl; + + set $tmp_file_dir "/file_upload/"; # 文件存储路径 + set $task_server "http://127.0.0.1:8080"; # task server host + + location / { + try_files $uri $uri/ /index.html; + proxy_set_header Host music-room.alchemy-studio.cn; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-Proto https; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Host $remote_addr; + } + + root /usr/local/openresty/nginx/html/music-room; + index index.html; + + location /api/ngx/test/hello_world { + #设置content type + default_type text/html ; + # HTTP Status Code 和 内容 + return 200 "hello world! "; + } + + + #Upload image files + location /api/ngx/image/upload { + content_by_lua_file /usr/local/openresty/resty_funcs/upload.lua; + } + #Combine image files + location /api/ngx/image/combine { + content_by_lua_file /usr/local/openresty/resty_funcs/combine.lua; + } + + location /api/v1/ws/ { + proxy_pass http://127.0.0.1:3001/api/v1/ws/; + proxy_set_header Host $host; + } + location /api/v1/uc/ { + proxy_pass http://127.0.0.1:3000/api/v1/uc/; + proxy_set_header Host $host; + } + location /api/v1/ts/ { + proxy_pass http://127.0.0.1:8080/api/v1/ts/; + proxy_set_header Host $host; + } + + ssl_certificate /etc/letsencrypt/live/music-room.alchemy-studio.cn/fullchain.pem; # managed by Certbot + ssl_certificate_key /etc/letsencrypt/live/music-room.alchemy-studio.cn/privkey.pem; # managed by Certbot +} diff --git a/prod/upload/combine.lua b/prod/upload/combine.lua new file mode 100644 index 0000000..3f0a36c --- /dev/null +++ b/prod/upload/combine.lua @@ -0,0 +1,5 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by moicen. +--- DateTime: 2021/9/4 12:28 +--- \ No newline at end of file diff --git a/prod/upload/upload.lua b/prod/upload/upload.lua index 85007c1..ab6e81d 100644 --- a/prod/upload/upload.lua +++ b/prod/upload/upload.lua @@ -1,27 +1,28 @@ --- local resty_sha1 = require "resty.sha1" local upload = require "resty.upload" --- opm get thibaultcha/lua-resty-jit-uuid local uuid = require "resty.jit-uuid" local cjson = require "cjson" local chunk_size = 4096 local form = upload:new(chunk_size) --- local sha1 = resty_sha1:new() uuid.seed() +local task_server = ngx.var.task_server +local file_dir = ngx.var.tmp_file_dir local file local file_name local files = {} + while true do local typ, res, err = form:read() if not typ then - ngx.say("failed to read: ", err) - return + ngx.say("failed to read: ", err) + return end if typ == "header" then - file_name = string.format("/tmp/%s.jpeg", uuid()) + file_name = string.format("%s/%s.jpeg", file_dir, uuid()) + ngx.log(ngx.ERR, "file name", file_name) if file_name then file = io.open(file_name, "w+") if not file then @@ -30,7 +31,7 @@ while true do end end - elseif typ == "body" then + elseif typ == "body" then if file then file:write(res) -- sha1:update(res) @@ -40,19 +41,17 @@ while true do file:close() file = nil table.insert(files, file_name) - -- local sha1_sum = sha1:final() - -- sha1:reset() - -- my_save_sha1_sum(sha1_sum) elseif typ == "eof" then local http = require "resty.http" local httpc = http.new() + local remote_url = string.format("%s/api/v1/ts/task_server/create_task", task_server) local res, err = httpc:request_uri( - "http://127.0.0.1:8080/api/v1/ts/task_server/create_task", + remote_url, { method = "POST", body = { - cjson.encode({task_type = 1, data = files}) + cjson.encode({task_type = 1, data = files, created_by = 'openresty'}) }, } ) diff --git a/test/test_var.lua b/test/test_var.lua new file mode 100644 index 0000000..40c8fee --- /dev/null +++ b/test/test_var.lua @@ -0,0 +1,8 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by moicen. +--- DateTime: 2021/9/4 12:20 +--- + +ngx.say('file dir...', ngx.var.tmp_file_dir) +ngx.say('task server...', ngx.var.task_server) \ No newline at end of file