【问题标题】:how to download excel file on nginx + tomcat reverse proxy?如何在 nginx + tomcat 反向代理上下载 excel 文件?
【发布时间】:2020-06-09 21:16:50
【问题描述】:

只是 tomcat 可以,但是不能用 nginx....

当我在 Tomcat 环境中使用 http://localhost:port 请求它时,它可以正常工作。但是在nginx反向代理环境下没有报错,file down也不行。

这是映射到 url /excel/clientSampleDownload 的 Spring Java 服务代码


//service code
public void downloadSampleExcelFileTms(HttpServletRequest request, HttpServletResponse response, Locale locale)throws Exception {
    ...
    SXSSFWorkbook wb = new SXSSFWorkbook();
    response.setHeader("Set-Cookie", "fileDownload=true; path=/");
    response.setHeader("Content-Disposition", String.format("attachment; 
    filename=\""+newString((saveFileName).getBytes("KSC5601"),"8859_1")+".xlsx\""));
    OutputStream outputStream=response.getOutputStream();
    wb.write(outputStream);
    wb.dispose();
    outputStream.close();
    wb.close();

}

这是 nginx 配置

//default.conf
server {
    listen       80;
    server_name  domain;

    client_max_body_size 2000M;

    location /manageChannel {
        proxy_pass http://localhost:19912;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Origin "";
    }

    location /resources/ {
        alias   /var/www/advertise.alancorp.co.kr/static/resources/;
        autoindex off;
        access_log off;
        expires 1M;
    }

    location / {
            proxy_set_header    Host $http_host;
            proxy_set_header    X-Real-IP $remote_addr;
            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header    X-Forwarded-Proto $scheme;
            proxy_set_header    X-NginX-Proxy true;
            proxy_pass http://localhost:19912;
            proxy_redirect      off;
            charset utf-8;
            # buffer size
            proxy_buffering   on;
            proxy_buffer_size    1024k;
            proxy_buffers        1024   1024k;
            client_body_buffer_size 1024k;
            proxy_busy_buffers_size 1024k;

    }
}

我应该在 nginx 配置中添加什么

【问题讨论】:

    标签: file nginx tomcat reverse-proxy xlsx


    【解决方案1】:

    我在这里得到了答案:https://gist.github.com/zeroasterisk/5535517

    我认为问题出在content-type 标头上。

    我的nginx版本是1.1.0,把application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx;加到conf/mime.types里面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-20
      • 1970-01-01
      • 2021-10-13
      • 1970-01-01
      • 1970-01-01
      • 2016-08-19
      • 2013-07-29
      • 1970-01-01
      相关资源
      最近更新 更多