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

Michael Butler asked:

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

My answer:


Using an alias would be fine, but you don’t need that regex crap on it.

location /minesweeper/ {
    alias /home/michael/sites/minesweeper/;
}

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.