documentation icon indicating copy to clipboard operation
documentation copied to clipboard

Nginx mime-type is not the same as Apache one

Open tzerber opened this issue 2 years ago • 1 comments

Hey everyone,

During other bug-hunting in the docker section, i noticed the mime-type in apache for js / mjs is the RFC correct one "text/javascript" but the nginx one is still "application/javascript" and it causes quite a lot of errors.
I know Nginx is not officially supported webserver, but it's commonly used with docker.

According to this the config claims to add

types {
        text/javascript js mjs;
    }

this to the config, but that causes errors in docker like

nginx: [warn] duplicate extension "js", content type: "text/javascript", previous content type: "application/javascript" in /etc/nginx/nginx.conf:19

As a somewhat temporary solution i changed the config like this to get rid of the errors

location ~* \.(?:js|mjs)$ {
            types { 
                text/javascript js mjs;
            } 
            try_files $uri /index.php$request_uri;
            add_header Cache-Control "public, max-age=15778463, $asset_immutable";
            access_log off;
        }

        # Serve static files
        location ~ \.(?:css|svg|gif|png|jpg|ico|wasm|tflite|map|ogg|flac)$ {
            try_files $uri /index.php$request_uri;
            add_header Cache-Control "public, max-age=15778463, $asset_immutable";
            access_log off;     # Optional: Don't log access to assets

            location ~ \.wasm$ {
                default_type application/wasm;
            }
        }

Not opening a pull request, because I'm not that much expert on nginx myself and i might be wrong here, but that fixed it. I believe after some time nginx will update their mime.types, but for the time being i think it's worth mentioning this in the docs, because only today I've seen at least 10 different people over at least 3 different issues having problems with that.

tzerber avatar Dec 14 '23 18:12 tzerber

Technically I'm fairly certain it's just a warning because we're redefining it, but I agree it would be nice to eliminate.

There's a relevant existing PR (#10408). Can you test the approach in #10408? It just drops js entirely from our base config.

I don't recall all the history at the moment, but for the record: https://trac.nginx.org/nginx/ticket/1407

joshtrichards avatar Dec 24 '23 21:12 joshtrichards