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 theContent-Type
from the extension. These are included from a file calledmime-types
. You can override this behaviour by placing adefault-type
directive in thelocation
block. For example:See this doucument for more.
Whether browser would render the page/download file finally depends on other factors, for example, 'Content-type' /'Content-Disposition' in http header
You may check and compare the http responses when visiting /hello/hi or /hello/hi.html, to examine that at least one of these two headers may not be correctly set, in this case it is more possibly content-type is not 'text/html' here
A solution would be specifying content-type for your path, may be like
or