博客
关于我
Nginx 配置服务器文件上传与下载
阅读量:790 次
发布时间:2023-02-15

本文共 4376 字,大约阅读时间需要 14 分钟。

基于Nginx的文件服务器搭建及应用

项目背景

在项目开发过程中,为了方便前端团队获取服务器端文件,搭建了基于Nginx的文件服务器。以下是搭建过程及相关配置记录。


1. 配置文件说明

Nginx配置文件位于/etc/nginx/nginx.conf,以下是核心配置内容:

user nginx;worker_processes auto;error_log /var/log/nginx/error.log;pid /run/nginx.pid;events {    worker_connections 1024;}http {    log_format main '$remote_addr - $remote_user [$time_local] "$request" '$status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"';    access_log /var/log/nginx/access.log main;    proxy_request_buffering off;  # 禁用请求缓冲(不加的话大文件上传可能会在前端报415)    proxy_buffering off;        # 禁用缓冲(不加的话大文件上传可能会在前端报415)    client_max_body_size 500M;  # 限制上传文件大小最大500MB    sendfile on;    tcp_nopush on;    tcp_nodelay on;    keepalive_timeout 65;    types_hash_max_size 2048;    include /usr/share/nginx/modules/*.conf;    include /etc/nginx/conf.d/*.conf;    server {        listen 9010;        server_name localhost;        charset utf-8;        include /etc/nginx/default.d/*.conf;        location / {            root /usr/local/oas/file;            sendfile on;            autoindex on;            autoindex_exact_size off;            autoindex_localtime on;        }    }    server {        listen 80 default_server;        listen [::]:80 default_server;        server_name localhost;        client_max_body_size 500M;        include /etc/nginx/default.d/*.conf;        location / {            root /usr/share/nginx/html/PaaS/;            try_files $uri /index.html;            index index.html;        }        location /ts/api {            proxy_set_header X-Real-IP $remote_addr;            proxy_pass http://10.12.1.206:31001/;        }        location /ts/others {            proxy_set_header X-Real-IP $remote_addr;            proxy_pass http://10.12.1.206:31001/others;        }        location /oas-cloud {            proxy_set_header X-Real-IP $remote_addr;            proxy_pass http://10.12.1.215:30103/oas-cloud;        }        location /zuul {            proxy_set_header X-Real-IP $remote_addr;            proxy_pass http://10.12.1.215:30103/zuul;        }        location /tengine {            proxy_pass http://127.0.0.1:8080/;        }        location /uum {            proxy_pass http://127.0.0.1:8081/;        }        location /cdc {            proxy_pass http://127.0.0.1:8082/;        }        location /upload {            proxy_set_header X-Real-IP $remote_addr;            proxy_pass http://127.0.0.1:9010/upload;        }        error_page 404 /404.html;        location = /40x.html {        }        error_page 500 502 503 504 /50x.html;        location = /50x.html {        }    }    server {        listen 8080;        server_name localhost;        client_max_body_size 500M;        include /etc/nginx/default.d/*.conf;        location / {            root /usr/share/nginx/html/tengine/;            try_files $uri /index.html;            index index.html;        }        error_page 404 /404.html;        location = /40x.html {        }        error_page 500 502 503 504 /50x.html;        location = /50x.html {        }    }    server {        listen 8081;        server_name localhost;        client_max_body_size 500M;        include /etc/nginx/default.d/*.conf;        location / {            root /usr/share/nginx/html/UUM/;            try_files $uri /index.html;            index index.html;        }        error_page 404 /404.html;        location = /40x.html {        }        error_page 500 502 503 504 /50x.html;        location = /50x.html {        }    }    server {        listen 8082;        server_name localhost;        client_max_body_size 500M;        include /etc/nginx/default.d/*.conf;        location / {            root /usr/share/nginx/html/CDC/;            try_files $uri /index.html;            index index.html;        }        error_page 404 /404.html;        location = /40x.html {        }        error_page 500 502 503 504 /50x.html;        location = /50x.html {        }    }}

2. 服务器验证

上传文件

将文件上传至/usr/local/oas/file/upload/sas/auth/目录下(文件名为20200303111734279),然后通过以下链接下载文件到本地:

http://113.98.58.42:9010/upload/sas/auth/20200303111734279

访问结果

通过访问服务器文件所在目录地址:

http://113.98.58.42:9010/

3. 注意事项

  • 文件上传优化

    配置中设置了以下优化参数,确保文件上传过程顺畅:

    proxy_request_buffering off;  # 禁用请求缓冲proxy_buffering off;        # 禁用缓冲client_max_body_size 500M;  # 限制上传文件大小
  • 访问地址

    服务器地址及端口信息:

    • 内网地址:10.12.1.215
    • 外网地址:113.98.58.42

通过以上配置及验证步骤,Nginx文件服务器已成功搭建完成,支持文件下载及相关服务访问。

转载地址:http://smcfk.baihongyu.com/

你可能感兴趣的文章
NAT网络地址转换配置详解
查看>>
Navicat for MySQL 命令列 执行SQL语句 历史日志
查看>>
Navicat for MySQL 查看BLOB字段内容
查看>>
Navicat Premium 12 卸载和注册表的删除
查看>>
Navicat 导入sql文件
查看>>
navicat 添加外键1215错误
查看>>
navicat 系列软件一点击菜单栏就闪退
查看>>
Navicat 设置时间默认值(当前最新时间)
查看>>
navicat 连接远程mysql
查看>>
navicat:2013-Lost connection to MySQL server at ‘reading initial communication packet解决方法
查看>>
Navicate for mysql 数据库设计-数据库分析
查看>>
Navicat下载和破解以及使用
查看>>
Navicat中怎样将SQLServer的表复制到MySql中
查看>>
navicat创建连接 2002-can‘t connect to server on localhost(10061)且mysql服务已启动问题
查看>>
Navicat可视化界面导入SQL文件生成数据库表
查看>>
Navicat向sqlserver中插入数据时提示:当 IDENTITY_INSERT 设置为 OFF 时,不能向表中的标识列插入显式值
查看>>
Navicat如何连接MySQL
查看>>
navicat怎么导出和导入数据表
查看>>
Navicat(数据库可视化操作软件)安装、配置、测试
查看>>
ndk特定版本下载
查看>>