Nginx:在Android上通过SSL提供静态文件

时间:2012-08-23 00:45:52

标签: android static nginx

我正在开发一个Web应用程序,它必须提供一些静态pdf文件。在桌面和iOS上一切都很好,但是不能在Android上下载静态文件。它只是挂起下载。以下是该图片的截图:

https://www.dropbox.com/s/r3qz9cia9vwwgam/2012-08-22%2020.38.37.png

Android版本为4.1.1

nginx版本是:

$ /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.2.3
built by gcc 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx-1.2.3 --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module

这是nginx配置的主要部分:

server {
    server_name .foosite.com;
    listen 443;

    ssl on;
    ssl_certificate /etc/ssl/certs/foo.crt;
    ssl_certificate_key /etc/ssl/private/foo.key;

    access_log logs/foo.log;

    gzip                on;
    gzip_http_version   1.0;
    gzip_comp_level     2;
    gzip_proxied        any;
    gzip_min_length     1100;
    gzip_buffers        16 8k;
    gzip_types          text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    # Some version of IE 6 don't handle compression well on some mime-types, so just disable for them
    gzip_disable "MSIE [1-6].(?!.*SV1)";

    # Set a vary header so downstream proxies don't send cached gzipped content to IE6
    gzip_vary on;

    location / {
        # some proxy_pass stuff here        
    }

    location /media {
        alias   /foo/path/to/media/;
        expires 1y;
    }
}

以下是我使用curl获得的响应标头:

$ curl -I https://foosite.com/media/path/to/foopdf.pdf
HTTP/1.1 200 OK
Server: nginx/1.2.3
Date: Thu, 23 Aug 2012 00:40:16 GMT
Content-Type: application/pdf
Content-Length: 136833
Last-Modified: Wed, 22 Aug 2012 21:14:50 GMT
Connection: keep-alive
Expires: Fri, 23 Aug 2013 00:40:16 GMT
Cache-Control: max-age=31536000
Accept-Ranges: bytes

我还试图通过提供用户代理头来模仿我的chrome浏览器:

$ curl -A "Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166  Safari/535.19" -I https://foosite.com/media/path/to/foopdf.pdf
HTTP/1.1 200 OK
Server: nginx/1.2.3
Date: Thu, 23 Aug 2012 00:33:09 GMT
Content-Type: application/pdf
Content-Length: 136833
Last-Modified: Wed, 22 Aug 2012 21:14:50 GMT
Connection: keep-alive
Expires: Fri, 23 Aug 2013 00:33:09 GMT
Cache-Control: max-age=31536000
Accept-Ranges: bytes

有关为何发生这种情况的任何想法?同样,这个问题只影响我的所有Android设备(Galaxy Nexus和Nexus 7)。在桌面和iOS设备上,它工作正常。如果我禁用SSL并通过端口80服务,那么一切正常。

谢谢。

0 个答案:

没有答案