title: Nginx: Serve static files over SSL on Android
body: <p>I am developing a web application which will have to serve some static pdf files. Everything works great on desktop and iOS however static files are not downloaded on Android. It just hangs the download. Here is the screenshot of how that looks:</p>
  
  <p><a href="https://www.dropbox.com/s/r3qz9cia9vwwgam/2012-08-22%2020.38.37.png" rel="nofollow">https://www.dropbox.com/s/r3qz9cia9vwwgam/2012-08-22%2020.38.37.png</a></p>
  
  <p>Android version is 4.1.1</p>
  
  <p>The nginx version is:</p>
  
  <pre><code>$ /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
  </code></pre>
  
  <p>Here is main portion of the nginx config:</p>
  
  <pre><code>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;
      }
  }
  </code></pre>
  
  <p>Here are the response headers I get using curl:</p>
  
  <pre><code>$ 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
  </code></pre>
  
  <p>I also tried to mimic my chrome android browser by providing the user agent header:</p>
  
  <pre><code>$ 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
  </code></pre>
  
  <p>Any ideas as to why this is happening? Again, this issue is only affecting all my android devices (Galaxy Nexus and Nexus 7). On desktop and iOS devices it works fine. And if I disable SSL and serve over port 80, then everything works fine.</p>
  
  <p>Thank you.</p>