2017-09-18 25 views
0

服务。在我的服务器块的apk文件中设置的头我有由nginx的

location/{ 
     proxy_pass http://echocdn; 
     include /etc/nginx/mime.types; 
     add_header Cache-Control "max-age=31536000, private, no-transform, no-cache"; 
     location ~* \.apk$ { 
     add_header Content-Type application/vnd.android.package-archive; 
     add_header Content-Disposition "attachment"; 
     } 
    } 

如果我删除了内部位置块,我能达到的APK文件(和所有其他文件)。

随着添加的块,任何.apk文件返回404.如何添加APK文件的标题?

注:内容类型为其他文件类型是由包含的mime.types处理好了,但即使我添加行APK文件所描述的How to download ".apk" as ".apk"? (not as ".zip")https://blog.mypapit.net/2015/08/how-to-set-apk-mime-type-for-nginx-web-server.html它只返回的内容类型的文本/ HTML的APK文件。

+0

你需要有APK块也在里面proxy_pass处理这个问题。 –

回答

0

您还需要在apk块内部有proxy_pass。 Nginx不能像编程语言那样工作,所以你不会执行父块中的任何内容。

而且使用default_type指令

location/{ 
     proxy_pass http://echocdn; 
     include /etc/nginx/mime.types; 
     #proxy_pass http://127.0.0.1:8082; 
     add_header Cache-Control "max-age=31536000, private, no-transform, no-cache"; 
     location ~* \.apk$ { 
     default_type application/vnd.android.package-archive; 
     add_header Content-Type application/vnd.android.package-archive; 
     add_header Content-Disposition "attachment"; 
     proxy_pass http://echocdn; 
     } 
    } 

设置内容类型,你甚至可以与如果

location/{ 
     proxy_pass http://echocdn; 
     include /etc/nginx/mime.types; 
     #proxy_pass http://127.0.0.1:8082; 
     add_header Cache-Control "max-age=31536000, private, no-transform, no-cache"; 
     if ($request_uri ~* \.apk$) { 
     default_type application/vnd.android.package-archive; 
     add_header Content-Type application/vnd.android.package-archive; 
     add_header Content-Disposition "attachment"; 
     } 
    } 
+0

在内部块中添加proxy_pass指令可以取消404 - 现在可以找到该文件,但Content-Type仍然是text/html。 –

+0

直到我删除了default_type指令(日志表示它不能在那里使用),if-directive选项才会启动。没有它,它的行为与其他选项相同 - 文件已收到但内容类型未设置。 –

+0

但内容配置设置为? –