Lucas P.
Lucas P.

Reputation: 4532

Nginx downloading file instead of serving it (Not PHP)

I'm trying to implement universal links from my iOS app, thus I need to have the "apple-app-site-association" file at the root of my web server.

I am using nginx and everything is (supposedly) setup correctly. My website works, php works, my api works. The only problem is that when I go to my site "test.com/apple-app-site-association" the browser (as well as the iOS browser) downloads the file instead of just displaying it, thus making my universal link not work.

If anyone has any ideas on how to stop nginx from offering the site as a download and serving it instead I would be glad.

Below is my server's configuration, with my site edited out:

server {
  listen 80 default_server;
  listen [::]:80 default_server;

  server_name test.com www.test.com;
  return 301 https://$server_name$request_uri;
}

server {
  # SSL configuration
  listen 443 ssl http2 default_server;
  listen [::]:443 ssl http2 default_server;

  include snippets/ssl-test.com.conf;
  include snippets/ssl-params.conf;

  client_max_body_size 1m;

  root /var/www/test.com/web;
  index  index.html index.htm index.php;

  access_log            /var/log/nginx/test.com.access.log;
  error_log             /var/log/nginx/test.com.error.log;

  #Default url rewrites
  location / {

    #root  /var/www/test.com/web;
    try_files $uri $uri/ /index.html;
    autoindex off;
    index  index.html index.htm index.php;

  }

  location ~ \.php$ {
    # try_files $uri =404;
    set $path_info $fastcgi_path_info;
    root  /var/www/test.com/web;
    fastcgi_index index.php;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    try_files $uri $uri/ /index.php$is_args$args;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;

    fastcgi_param SCRIPT_FILENAME $request_filename;
    fastcgi_param APP_ENV dev;

  }

  #Apple universal links
  location = /apple-app-site-association {
    default_type application/pkcs7-mime;
  }

  #Redirect all requests under /user/ to the "get App" page
  location /user/ {
    return 301 https://test.com/get_app.html;
    # try_files $uri $uri/ /get_app.html;
  }

  #Let's Encrypt SSL Validation
  include snippets/letsencrypt.conf;
}

Using a REST API client, requesting the file gives the following headers, that appear to be correct (no "attachment" header):

Server: nginx/1.10.3
Date: Sun, 02 Apr 2017 17:25:42 GMT
Content-Type: application/pkcs7-mime
Content-Length: 149
Last-Modified: Sun, 02 Apr 2017 16:07:02 GMT
Connection: keep-alive
Etag: "58e121a6-95"
Strict-Transport-Security: max-age=63072000; includeSubdomains
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
Accept-Ranges: bytes

Upvotes: 0

Views: 1511

Answers (1)

Ravindra HV
Ravindra HV

Reputation: 2608

Your browser as well as the ios browser may not support the Content-Type: application/pkcs7-mime. If the content is human readable try setting Content-Type: text/plain.

Also see if this link is of any help.

Upvotes: 1

Related Questions