为什么请求没有文件扩展名后缀html将下载文件? [英] Why request without suffix of filename extension html will download file?

查看:220
本文介绍了为什么请求没有文件扩展名后缀html将下载文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想测试nginx的echo模块。我想回显我在浏览器中键入的网址。



我的nginx配置:

  index index.php index.html index.htm index.nginx-debian .html; 

位置/ {
try_files $ uri $ uri / /index.php=404;
}
位置/你好{
echo $ request_uri;






输入网址: http://127.0.0.1/hello/。



返回:返回文件和该文件的内容为: / hello /






输入网址: http://127.0.0.1/hello/hi



返回:返回文件和文件有内容: / hello / hi






输入网址: http://127.0.0.1/hello/hi.html



返回:打印浏览器中的 /hello/hi.html






我的问题:
为什么没有html后缀的网址会变成下载文件?
如何解决它?
我只想在浏览器中打印网址。

解决方案

nginx 决定了 Content-Type 来自分机。这些包含在名为 mime-types 的文件中。您可以通过在位置块中放置 default-type 指令来覆盖此行为。例如:

  location / hello {
types {}
default_type text / html;
echo $ request_uri;
}

请参阅 this doucument for more。


I want to test the nginx‘s echo module.And I want to echo the url of what I type in browser.

My nginx configuration:

   index  index.php index.html index.htm index.nginx-debian.html ;

   location / {               
       try_files $uri $uri/  /index.php  =404;              
   }
   location  /hello {
   echo $request_uri;
   }


input url : http://127.0.0.1/hello/.

return : return a file and the file have content : /hello/


input url: http://127.0.0.1/hello/hi

return : return a file and the file have content : /hello/hi


input url:http://127.0.0.1/hello/hi.html

return: print /hello/hi.html in browser.


My question: Why the url without the html suffix will become download file? How to fix it ? I just want to print the url in browser.

解决方案

nginx determines the Content-Type from the extension. These are included from a file called mime-types. You can override this behaviour by placing a default-type directive in the location block. For example:

location  /hello {
    types {}
    default_type    text/html;
    echo $request_uri;
}

See this doucument for more.

这篇关于为什么请求没有文件扩展名后缀html将下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆