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