Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
O
openresty-static-server
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
AFA_展荣臻
openresty-static-server
Commits
50fd4a3e
提交
50fd4a3e
authored
7月 05, 2026
作者:
AFA_ZHANRONGZHEN
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
解决线上上传时上传目录不存在的问题
上级
279bec0a
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
53 行增加
和
4 行删除
+53
-4
Dockerfile
Dockerfile
+3
-1
nginx.conf
nginx.conf
+50
-3
没有找到文件。
Dockerfile
浏览文件 @
50fd4a3e
...
@@ -8,6 +8,9 @@ RUN rm /usr/local/openresty/nginx/conf/nginx.conf
...
@@ -8,6 +8,9 @@ RUN rm /usr/local/openresty/nginx/conf/nginx.conf
COPY
detect_mime_by_magic.lua /usr/local/openresty/lualib/
COPY
detect_mime_by_magic.lua /usr/local/openresty/lualib/
COPY
nginx.conf /usr/local/openresty/nginx/conf/
COPY
nginx.conf /usr/local/openresty/nginx/conf/
# 创建上传目录,运行时还会按 clientId 自动创建子目录
RUN
mkdir
-p
/var/www/html/upload
&&
chmod
777 /var/www/html/upload
# 创建日志文件并设置权限
# 创建日志文件并设置权限
RUN
touch
/usr/local/openresty/nginx/logs/access.log
&&
chmod
777 /usr/local/openresty/nginx/logs/access.log
&&
\
RUN
touch
/usr/local/openresty/nginx/logs/access.log
&&
chmod
777 /usr/local/openresty/nginx/logs/access.log
&&
\
touch
/usr/local/openresty/nginx/logs/error.log
&&
chmod
777 /usr/local/openresty/nginx/logs/error.log
&&
\
touch
/usr/local/openresty/nginx/logs/error.log
&&
chmod
777 /usr/local/openresty/nginx/logs/error.log
&&
\
...
@@ -16,4 +19,3 @@ RUN touch /usr/local/openresty/nginx/logs/access.log && chmod 777 /usr/local/ope
...
@@ -16,4 +19,3 @@ RUN touch /usr/local/openresty/nginx/logs/access.log && chmod 777 /usr/local/ope
# 启动openresty服务
# 启动openresty服务
CMD
["/usr/local/openresty/bin/openresty", "-g", "daemon off;"]
CMD
["/usr/local/openresty/bin/openresty", "-g", "daemon off;"]
nginx.conf
浏览文件 @
50fd4a3e
...
@@ -262,6 +262,44 @@ http {
...
@@ -262,6 +262,44 @@ http {
local
filepath
=
nil
local
filepath
=
nil
local
file_size
=
0
local
file_size
=
0
local
upload_dir
=
"/var/www/html/upload/"
local
upload_dir
=
"/var/www/html/upload/"
local
lfs
=
require('lfs_ffi')
local
function
sanitize_path_segment(value,
fallback)
if
not
value
or
value
==
""
then
return
fallback
end
local
sanitized
=
string.gsub(value,
"[/
\\
:
%z]",
"_")
sanitized
=
string.gsub(sanitized,
"%.%.",
"_")
if
sanitized
==
""
or
sanitized
==
"."
or
sanitized
==
".."
then
return
fallback
end
return
sanitized
end
local
function
ensure_dir(path)
local
current
=
""
for
segment
in
string.gmatch(path,
"[^/]+")
do
current
=
current
..
"/"
..
segment
local
attr
=
lfs.attributes(current)
if
attr
then
if
attr.mode
~
=
"directory"
then
return
nil,
current
..
"
is
not
a
directory"
end
else
local
ok,
mkdir_err
=
lfs.mkdir(current)
if
not
ok
then
attr
=
lfs.attributes(current)
if
not
attr
or
attr.mode
~
=
"directory"
then
return
nil,
mkdir_err
end
end
end
end
return
true
end
while
true
do
while
true
do
local
typ,
res,
read_err
=
form:read()
local
typ,
res,
read_err
=
form:read()
...
@@ -283,12 +321,21 @@ http {
...
@@ -283,12 +321,21 @@ http {
elseif
typ
==
"body"
then
elseif
typ
==
"body"
then
if
filename
and
not
file
then
if
filename
and
not
file
then
if
client_id
then
if
client_id
then
upload_dir
=
upload_dir
..
client_id
..
"/"
upload_dir
=
upload_dir
..
sanitize_path_segment(client_id,
"anonymous")
..
"/"
end
local
ok,
mkdir_err
=
ensure_dir(upload_dir)
if
not
ok
then
ngx.log(ngx.ERR,
"failed
to
create
upload
dir:
",
upload_dir,
",
error:
",
mkdir_err)
ngx.status
=
ngx.HTTP_INTERNAL_SERVER_ERROR
ngx.say("failed
to
create
upload
directory")
return
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
end
end
filename
=
sanitize_path_segment(filename,
"upload.bin")
filepath
=
upload_dir
..
filename
filepath
=
upload_dir
..
filename
file
=
io.open(filepath,
"wb")
local
open_err
file,
open_err
=
io.open(filepath,
"wb")
if
not
file
then
if
not
file
then
ngx.log(ngx.ERR,
"failed
to
open
file:
",
filepath)
ngx.log(ngx.ERR,
"failed
to
open
file:
",
filepath
,
",
error:
",
open_err
)
ngx.status
=
ngx.HTTP_INTERNAL_SERVER_ERROR
ngx.status
=
ngx.HTTP_INTERNAL_SERVER_ERROR
ngx.say("failed
to
create
file")
ngx.say("failed
to
create
file")
return
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
return
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论