Nginx fails to load css files
I found an workaround on the web. I added to /etc/nginx/conf.d/default.conf the following:
location ~ \.css {
add_header Content-Type text/css;
}
location ~ \.js {
add_header Content-Type application/x-javascript;
}
The problem now is that a request to my css file isn't redirected well, as if root is not correctly set.
In error.log I see
2012/04/11 14:01:23 [error] 7260#0: *2 open() "/etc/nginx//html/style.css"
So as a second workaround I added the root to each defined location.
Now it works, but seems a little redundant. Isn't root inherited from / location ?
CSS was not loaded because its MIME type
It is usual to place include mime.types;
inside the outer http { ... }
block, rather than inside a location { ... }
block, so that it is system-wide and inherited by all server { ... }
blocks and all locations.
Your href="../static/css/
statement is relative, so from the information you provide, we cannot tell whether the URI is being processed by the location /static/
block or the location /
block.
You do not have a root
(or alias
) defined for the location /
block, so the false condition of the if (!-f $request_filename)
statement will probably always fail with 404.
You may want to set root /var/www/test/my-example
in the server { ... }
block and allow it to be inherited by some location
blocks. The use of alias
where a root
can be used is discouraged - see this document.
If your CSS files are being served through the proxy_pass http://test_server;
then this is the wrong place to be fixing the MIME type.
Related Topics
Jqueryui Slider: Absolutely Positioned Element & Parent Container Height
Background Image Is Not Displayed in Firefox
Wrapping a Text Around a Circular Element
CSS Problem with Background-Attachment:Fixed;
Why Do Inline Elements Behave Like Block Level Elements When Floated
Is There a CSS Selector for the First Child, Taking Text Nodes into Account
Javafx CSS Border-Radius Issue
CSS Flex, How to Display One Item on First Line and Two on the Next Line
How to Specify Font Attributes for All Elements on an HTML Web Page
How to Gulp-Watch Multiple Files
How to Display CSS3 Columns on Ie
Have Text Scale Up in Size to Fit the Container
Css: Height- Fill Out Rest of Div
Cross-Browser Issue: Min-Height and Collapsing Margins
Datagrid/Celltable Styling Frustration -- Overriding Row Styles
Bootstrap 4.1 - to Get Grid System Only