2017-04-02 123 views
0

我試圖從我的iOS應用程序實現通用鏈接,因此我需要在我的Web服務器的根目錄的「蘋果應用程序網站協會」文件。Nginx的下載文件,而不是服務它(不是PHP)

我正在使用nginx,一切都(據說)設置正確。我的網站工作,PHP作品,我的API作品。唯一的問題是,當我去我的網站「test.com/apple-app-site-association」瀏覽器(以及iOS瀏覽器)下載文件,而不是隻顯示它,從而使我的通用鏈接無法正常工作。

如果任何人有任何想法如何阻止nginx提供網站作爲下載和服務,而不是我會很高興。

下面是我的服務器的配置,與我的網站編輯了:

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; 
} 

使用REST API客戶端,請求文件給出了下面的標題,這似乎是正確的(沒有「附件」標頭):

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 
+1

你有沒有試過'內容處理:內聯' – Deadooshka

+0

非常感謝!添加'add_header Content-Disposition inline;'和'default_type application/json'之後,該文件就可以正確傳送了! –

回答

0

您的瀏覽器以及ios瀏覽器可能不支持Content-Type: application/pkcs7-mime。如果內容是人類可讀的,請嘗試設置Content-Type: text/plain

另請參閱this link是否有幫助。

相關問題