Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
O
openresty-static-server
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
AFA_展荣臻
openresty-static-server
Commits
b16e35d0
提交
b16e35d0
authored
5月 11, 2026
作者:
zhanrongzhen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加
http://192.168.8.103:8080/fileserver/upload?clientId=client001
接口
上级
9a68a4b2
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
112 行增加
和
4 行删除
+112
-4
nginx.conf
nginx.conf
+112
-4
没有找到文件。
nginx.conf
浏览文件 @
b16e35d0
...
...
@@ -20,6 +20,10 @@ http {
server_name
localhost
;
access_log
logs/access
.log
main_with_time
;
error_log
logs/error
.log
warn
;
client_max_body_size
1g
;
client_body_buffer_size
20m
;
gzip
on
;
gzip_comp_level
6
;
gzip_types
...
...
@@ -160,16 +164,120 @@ http {
}
location
/download/
{
internal
;
# 标记为内部 location,不允许外部直接访问
alias
/var/www/html/resources/default/
;
# 设置文件根目录
internal
;
alias
/var/www/html/resources/default/
;
expires
1d
;
add_header
Accept-Ranges
bytes
;
sendfile
on
;
}
# 未匹配的请求
location
/fileserver/upload
{
if
(
$request_method
=
'OPTIONS')
{
add_header
'Access-Control-Allow-Origin'
'*'
;
add_header
'Access-Control-Allow-Methods'
'POST,
OPTIONS'
;
add_header
'Access-Control-Allow-Headers'
'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'
;
add_header
'Access-Control-Max-Age'
1728000
;
add_header
'Content-Type'
'text/plain
;
charset=utf-8'
;
add_header
'Content-Length'
0
;
return
204
;
}
content_by_lua_block
{
ngx.header["Access-Control-Allow-Origin"]
=
"*"
ngx.header["Access-Control-Allow-Methods"]
=
"POST,
OPTIONS"
ngx.header["Access-Control-Allow-Headers"]
=
"DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range"
local
upload
=
require
"resty.upload"
local
cjson
=
require
"cjson"
local
client_id
=
ngx.var.arg_clientId
local
chunk_size
=
4096
local
form,
err
=
upload:new(chunk_size)
if
not
form
then
ngx.log(ngx.ERR,
"failed
to
new
upload:
",
err)
ngx.status
=
ngx.HTTP_INTERNAL_SERVER_ERROR
ngx.say("upload
failed")
return
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
end
form:set_timeout(60000)
local
filename
=
nil
local
file
=
nil
local
filepath
=
nil
local
file_size
=
0
local
upload_dir
=
/var/www/html/upload
while
true
do
local
typ,
res,
err
=
form:read()
if
not
typ
then
ngx.log(ngx.ERR,
"failed
to
read:
",
err)
break
end
if
typ
==
"header"
then
local
header_name
=
res[1]
local
header_value
=
res[2]
if
header_name
==
"Content-Disposition"
then
local
filename_match
=
string.match(header_value,
'filename="([^"]+)"')
if
filename_match
then
filename
=
filename_match
end
end
elseif
typ
==
"body"
then
if
filename
and
not
file
then
if
client_id
then
upload_dir
=
upload_dir
..
client_id
..
"/"
end
filepath
=
upload_dir
..
filename
file
=
io.open(filepath,
"wb")
if
not
file
then
ngx.log(ngx.ERR,
"failed
to
open
file:
",
filepath)
ngx.status
=
ngx.HTTP_INTERNAL_SERVER_ERROR
ngx.say("failed
to
create
file")
return
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
end
end
if
file
then
file:write(res)
file_size
=
file_size
+
#res
end
elseif
typ
==
"part_end"
then
if
file
then
file:close()
file
=
nil
end
filename
=
nil
elseif
typ
==
"eof"
then
break
end
end
if
filepath
and
file_size
>
0
then
ngx.header["Content-Type"]
=
"application/json"
ngx.say(cjson.encode(
{
success
=
true,
message
=
"file
uploaded
successfully",
client_id
=
client_id,
filepath
=
filepath,
filesize
=
file_size
}
))
else
ngx.status
=
ngx.HTTP_BAD_REQUEST
ngx.header["Content-Type"]
=
"application/json"
ngx.say(cjson.encode(
{
success
=
false,
message
=
"no
file
uploaded"
}
))
end
}
}
location
/
{
return
404
;
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论