DockerFile
FROM centos:centos7
RUN yum -y update
RUN yum -y install gcc gcc-c++ autoconf automake make
RUN yum -y install zlib zlib-devel openssl* pcre* wget lua-devel
RUN yum -y install unzip
# nginx base
ADD nginx-1.18.0.tar.gz /tmp
# nginx_upload_steam
ADD nginx-upload-module-2.3.0.tar.gz /tmp
ADD up.html /tmp
ADD nginx.conf /tmp
WORKDIR /tmp
#RUN tar zxvf 2.3.0.tar.gz
#编译安装Nginx
RUN useradd -M -s /sbin/nologin nginx
RUN mkdir -p /usr/local/nginx
RUN cd /tmp/nginx-1.18.0 \
&& ./configure --prefix=/etc/nginx --user=nginx --group=nginx --conf-path=/tmp/nginx.conf --with-http_ssl_module --with-http_stub_status_module --error-log-path=/tmp/error.log --http-log-path=/tmp/access.log --add-module=/tmp/nginx-upload-module-2.3.0 \
&& make && make install
#参数说明
RUN /etc/nginx/sbin/nginx -c /tmp/nginx.conf
RUN ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
#EXPOSE 映射端口
EXPOSE 88
#CMD 运行以下命令
#CMD ["nginx"]
CMD ["/etc/nginx/sbin/nginx","-g","daemon off;"]
nginx 配置文件
worker_processes 20;
events {
worker_connections 1024;
}
http{
default_type application/octet-stream;
server{
listen 88;
server_name localhost;
client_max_body_size 1024m;
location /upload {
upload_store /tmp; # 文件上传目录
upload_pass /deltaManagerDeltaUpload; # 转发到 location /deltaManagerDeltaUpload】
upload_store_access user:rw; #临时文件权限
upload_resumable on; #断点续传
add_header From localhost;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header Referer $http_referer;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
upload_limit_rate 10240k;
upload_set_form_field "${upload_field_name}_name" $upload_file_name;
upload_set_form_field "${upload_field_name}_content_type" $upload_content_type;
upload_set_form_field "${upload_field_name}_path" $upload_tmp_path;
upload_aggregate_form_field "${upload_field_name}_md5" $upload_file_md5;
upload_aggregate_form_field "${upload_field_name}_size" $upload_file_size;
upload_pass_form_field "^.*$"; #表单参数
upload_pass_args on; #转发参数
upload_cleanup 400 404 499 500-505; #如果出现这些错误将删除保存的文件
}
location /deltaManagerDeltaUpload {
proxy_pass http://ip:port/video/upload; # 后端接收上传信息的实际接口
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header Referer $http_referer;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location / {
root /tmp;
}
}
}
docker执行文件
docker stop upload
docker rm upload
docker build -t upload -f Dockerfile .
docker run -d -p 88:88 -e TZ=Asia/Shanghai --network network --name upload upload
测试文件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>upload</title>
</head>
<body>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<form name="upload" method="POST" enctype="multipart/form-data" action="upload">
<input type="file" name="file"/>
<input type="text" name="content" value="啊啊啊啊啊啊"/>
<input type="submit" name="submit" value="Upload"/>
</form>
</body>
</html>
需要下载的文件
http://nginx.org/download/nginx-1.18.0.zip
https://codeload.github.com/fdintino/nginx-upload-module/tar.gz/2.3.0
存放到同一个目录中
如何 不想 使用 这种比较 原始的搭建方法 可以使用第三方的
DockerFile :
FROM dimka2014/nginx-upload-with-progress-modules
MAINTAINER laowang
COPY nginx.conf /etc/nginx/nginx.conf
ADD up.html /tmp
EXPOSE 88
其他的保持一致就好了。