Nginx – Why is nginx serving the wrong MIME-type for requests in directory alias

nginx

If there is a way to do this typical task without using aliases, I'm all for it.

I want all requests at the /minesweeper/* URL to be pulled from a completely different directory than other requests. The following configuration WORKS, files are served, but the MIME-type is application/octet-stream instead of what it should be (i.e. text/css). With the incorrect MIME type, it is impossible for web browsers to render the CSS styles in the document.

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;
    }
}

Best Answer

I fixed the problem by NOT using an alias. ALSO I had to DELETE the cache in Chrome or else it wasn't actually getting the new MIME types! I checked in Firefox and it worked.

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;
    }

}