4

Nginx修改默认Content-Type值,解决服务器文件没有扩展名时变为下载的问题

 1 year ago
source link: https://blog.p2hp.com/archives/9374
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Nginx修改默认Content-Type值,解决服务器文件没有扩展名时变为下载的问题 | Lenix Blog

1、Nginx 安装之后 default_type的值默认配置为 application/octet-stream,而且目前已经配置很多域名,贸然的去修改这样的全局配置,可能应发不可用的问题

2、html结尾的文件,放到网站根目录下默认会被识别响应为 text/html.

3、但是今天反馈的文件是没有后缀的,所以默认就成了 application/octet-stream, 浏览器请求会直接进行下载,而不是展示文件内容

4、针对该文件进行单独的配置,如下

server {
include local_ssl_port.conf;
include ssl/ssl.conf;
server_name xxx.somedomain.com;
root /data/project/blog;
include expires.conf;
location / {
# 这里单独针对性的配置 default_type 为要求的格式
default_type text/html;
server {
    include local_ssl_port.conf;
    include ssl/ssl.conf;
    server_name    xxx.somedomain.com;
    root    /data/project/blog;
    include         expires.conf;

    location / {
        # 这里单独针对性的配置 default_type 为要求的格式
        default_type text/html;
    }
}

5、再次浏览器测试,展示为文件内容


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK