modify local dev config & make openresty directy upload combine file to upyun
This commit is contained in:
@@ -2,13 +2,13 @@ server {
|
||||
# https://serverfault.com/questions/798734/use-variable-for-server-name-in-nginx#
|
||||
# server_name $servername;
|
||||
server_name "admin.localhost";
|
||||
listen 80;
|
||||
listen 8088;
|
||||
client_max_body_size 10M;
|
||||
|
||||
set $tmp_file_dir "/usr/local/file_upload/"; # 文件存储路径
|
||||
set $tmp_file_dir "/usr/local/file_upload"; # 文件存储路径
|
||||
set $task_server "http://127.0.0.1:8080"; # task server host
|
||||
set $htyuc "http://127.0.0.1:3000"; #htyuc host
|
||||
set $resty_loc "/usr/local/opt/openresty/";
|
||||
set $resty_loc "/usr/local/opt/openresty";
|
||||
set $convert "/usr/local/bin/convert";
|
||||
set $upyun_operator "moicen";
|
||||
set $upyun_password "NyJ51zRwFApY9Wo9EHJMrb8GI9YtvpVN";
|
||||
@@ -40,23 +40,23 @@ server {
|
||||
|
||||
#Upload image files
|
||||
location /api/ngx/image/upload {
|
||||
content_by_lua_file $resty_loc/resty_funcs/upload.lua;
|
||||
content_by_lua_file $resty_loc/nginx/scripts/upload.lua;
|
||||
}
|
||||
#Combine image files
|
||||
location /api/ngx/image/combine {
|
||||
content_by_lua_file $resty_loc/resty_funcs/combine.lua;
|
||||
content_by_lua_file $resty_loc/nginx/scripts/combine.lua;
|
||||
}
|
||||
#Audio file download
|
||||
location /api/ngx/audio/upload {
|
||||
content_by_lua_file $resty_loc/resty_funcs/upload_audio.lua;
|
||||
content_by_lua_file $resty_loc/nginx/scripts/upload_audio.lua;
|
||||
}
|
||||
#Audio file convert
|
||||
location /api/ngx/audio/convert {
|
||||
content_by_lua_file $resty_loc/resty_funcs/convert_audio.lua;
|
||||
content_by_lua_file $resty_loc/nginx/scripts/convert_audio.lua;
|
||||
}
|
||||
|
||||
location /api/ngx/convert/test {
|
||||
content_by_lua_file $resty_loc/resty_funcs/test.lua;
|
||||
content_by_lua_file $resty_loc/nginx/scripts/test.lua;
|
||||
}
|
||||
|
||||
location /api/v1/ws/ {
|
||||
|
||||
@@ -3,7 +3,7 @@ server {
|
||||
# https://serverfault.com/questions/798734/use-variable-for-server-name-in-nginx#
|
||||
# server_name $servername;
|
||||
server_name "music-room.localhost";
|
||||
listen 80;
|
||||
listen 8088;
|
||||
client_max_body_size 10M;
|
||||
|
||||
set $resty_loc "/usr/local/opt/openresty";
|
||||
|
||||
@@ -2,7 +2,7 @@ server {
|
||||
# https://serverfault.com/questions/798734/use-variable-for-server-name-in-nginx#
|
||||
# server_name $servername;
|
||||
server_name "ts.localhost";
|
||||
listen 80;
|
||||
listen 8088;
|
||||
client_max_body_size 10M;
|
||||
|
||||
set $task_server "http://127.0.0.1:8080"; # task server host
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/bin/sh
|
||||
set -x
|
||||
|
||||
mkdir -p /usr/local/etc/openresty/conf.d
|
||||
cp conf/local_macos/*.conf /usr/local/etc/openresty/conf.d/
|
||||
openresty_sub_config_dir=/usr/local/etc/openresty/conf.d
|
||||
|
||||
cp scripts/*.lua /usr/local/opt/openresty/resty_funcs/
|
||||
mkdir -p $openresty_sub_config_dir
|
||||
|
||||
cp conf/local_macos/*.conf $openresty_sub_config_dir
|
||||
|
||||
+40
-5
@@ -1,7 +1,41 @@
|
||||
-- 指定模块引用目录,否则无法加载同目录下的其他文件
|
||||
package.path = package.path .. ';/usr/local/opt/openresty/nginx/scripts/?.lua';
|
||||
local uuid = require "resty.jit-uuid"
|
||||
local cjson = require "cjson"
|
||||
local strip_path = require("strip_path")
|
||||
local Upyun = require('upyun')
|
||||
uuid.seed()
|
||||
|
||||
local function upload(filepath)
|
||||
local upyun, err = Upyun:new({
|
||||
user = ngx.var.upyun_operator,
|
||||
passwd = ngx.var.upyun_password,
|
||||
localFilePath = filepath
|
||||
})
|
||||
|
||||
if not upyun then
|
||||
ngx.status = 500
|
||||
ngx.log(ngx.ERR, "failed to initialize upyun: " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
local bucket = ngx.var.upyun_bucket
|
||||
local directory = ngx.var.upyun_directory
|
||||
local filename = strip_path.strip_path(filepath)
|
||||
|
||||
local savePath = bucket .. "/" .. directory .. "/" .. filename
|
||||
|
||||
local info, err = upyun:upload_file(savePath, nil, nil)
|
||||
if not info then
|
||||
ngx.status = 502
|
||||
ngx.log(ngx.ERR, "failed to upload file : " .. err)
|
||||
return
|
||||
else
|
||||
ngx.status = 200
|
||||
ngx.say(ngx.var.upyun_cdn .. directory .. "/" .. filename)
|
||||
end
|
||||
end
|
||||
|
||||
local file_dir = ngx.var.tmp_file_dir
|
||||
ngx.req.read_body()
|
||||
local req_body = cjson.decode(ngx.req.get_body_data())
|
||||
@@ -32,12 +66,13 @@ local cmd = convert .. " -append " .. table.concat(origin, " ") .. " " .. combin
|
||||
ngx.log(ngx.INFO, 'CMD -> ', cmd)
|
||||
local result, _, code = os.execute(cmd)
|
||||
if result and code == 0 then
|
||||
local file = io.open(combined)
|
||||
local content = file:read("*all")
|
||||
file:close()
|
||||
os.remove(combined)
|
||||
|
||||
ngx.log(ngx.INFO, "IMAGE COMBINED -> ", combined)
|
||||
ngx.say(content)
|
||||
|
||||
ngx.log(ngx.INFO, "Upload combined image " .. combined .. " to upyun .")
|
||||
|
||||
upload(combined)
|
||||
|
||||
else
|
||||
ngx.status = 500
|
||||
ngx.log(ngx.ERR, "IMAGE COMBINE *FAILED*")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
-- 指定模块引用目录,否则无法加载同目录下的其他文件
|
||||
package.path = package.path .. ';/usr/local/openresty/nginx/scripts/?.lua';
|
||||
package.path = package.path .. ';/usr/local/opt/openresty/nginx/scripts/?.lua';
|
||||
local cjson = require "cjson"
|
||||
local uuid = require "resty.jit-uuid"
|
||||
local http = require "resty.http"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package.path = package.path .. ';/usr/local/openresty/nginx/scripts/?.lua';
|
||||
package.path = package.path .. ';/usr/local/opt/openresty/nginx/scripts/?.lua';
|
||||
local yun = require("upyun")
|
||||
local cjson = require "cjson"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user