Home > Web Front-end > CSS Tutorial > Why Doesn\'t My Nginx Server Load CSS Files Despite Correct MIME Type Settings?

Why Doesn\'t My Nginx Server Load CSS Files Despite Correct MIME Type Settings?

Patricia Arquette
Release: 2024-12-10 06:29:17
Original
227 people have browsed it

Why Doesn't My Nginx Server Load CSS Files Despite Correct MIME Type Settings?

Nginx Fails to Load CSS Files

Issue:
When loading a website after switching from Apache2 to Nginx, users encounter an error indicating that CSS files cannot be loaded due to an incorrect MIME type. Despite correct MIME type settings in /etc/nginx/mime.types, the error persists.

Explanation:
The include /etc/nginx/mime.types; directive should be placed under the server block, not under the http block.

Solution:
To resolve the issue, modify the default server configuration file (/etc/nginx/conf.d/default.conf) as follows:

server {
    listen       80;
    server_name  localhost;

    location / {
        include              /etc/nginx/mime.types; # Move this directive here
        root                /usr/share/nginx/html;
        index                index.html index.htm index.php;
        fastcgi_pass        127.0.0.1:9000;
        fastcgi_index        index.php;
        fastcgi_param        SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
        include             fastcgi_params;
    }

    # Rest of the server block remains unchanged
}
Copy after login

Additional Information:
The include /etc/nginx/mime.types; directive is used to include the MIME type configuration from a separate file. Placing it under the server block ensures that the MIME type settings are applied specifically to the current server configuration.

The above is the detailed content of Why Doesn\'t My Nginx Server Load CSS Files Despite Correct MIME Type Settings?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template