nginx配置让任何文件在浏览器中显示文本text/plain
- 2019 年 10 月 5 日
- 筆記
http://www.sijitao.net/1879.html?utm_source=tuicool&utm_medium=referral
例如配置1.plist类型的文件,让他在浏览器中直接打开,而不是下载。
方法一:
修改mime.types,添加plist扩展名为text/plain类型,直接显示文本。
在文件中添加如下内容
text/plain plist;

修改好mime.types类型后,直接重启nginx即可。这个方法修改后影响所有nginx网站的配置。
方法二:
单独打开某个网站的配置文件,在server中修改,例如我让某个网站ios目录下的plist文件显示为text/plain格式。
location ~ .*/ios/.*.plist$ { add_header Content-Type text/plain;}
让某个目录下的文件都显示为text/plain格式。
# Target codelocation /code/ { # All files in it location ~* { add_header Content-Type text/plain; }}
修改后重启nginx。
参考网址:http://clubmate.fi/display-any-file-in-a-browser-as-plain-text/