Skip to content

Nginx mime-type is not the same as Apache one #11400

@tzerber

Description

@tzerber

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions