为什么 nginx 为目录别名中的请求提供错误的 MIME 类型?

Mic*_*ler 5 nginx

如果有一种方法可以在不使用别名的情况下完成这个典型的任务,我完全支持它。

我希望/minesweeper/*URL 上的所有请求都从与其他请求完全不同的目录中提取。以下配置有效,文件已提供,但 MIME 类型是 application/octet-stream 而不是应有的类型(即 text/css)。如果 MIME 类型不正确,Web 浏览器就无法呈现文档中的 CSS 样式。

nginx.conf:
http {
    index index.html
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    ...
}

virtual.conf:
server {
    listen       *:80;
    server_name  djmp.org www.djmp.org;
    root   /home/devsites/djmp.org/public_html/;
    index  index.html;


    location ~ ^/minesweeper($|/.*) {
        alias /home/michael/sites/minesweeper$1;
    }
}
Run Code Online (Sandbox Code Playgroud)

Mic*_*ler 1

我通过不使用别名解决了这个问题。另外我必须删除 Chrome 中的缓存,否则它实际上并没有获得新的 MIME 类型!我检查了 Firefox 并且它有效。

server {
    listen       *:80;
    server_name  djmp.org www.djmp.org;
    root   /home/devsites/djmp.org/public_html/;
    index  index.html;
    include       /etc/nginx/mime.types;

    location /minesweeper {
            root   /home/michael/sites/;  # choose the parent directory here
            index  index.html index.htm;
    }

}
Run Code Online (Sandbox Code Playgroud)