Nginx – WordPress blog on Rails loads styles and scripts with mime type text/html
Posted by: admin November 7, 2017 Leave a comment
I just installed a WordPress blog under a /blog directory within a Rails app, running on Unicorn and Nginx, and my stylesheets and scripts aren’t being loaded properly in the browser when I go to my domain.com/blog pages. Chrome console’s giving me the following error:
- Resource interpreted as Stylesheet but transferred with MIME type text/html
- Resource interpreted as Script but transferred with MIME type text/html
Have been trying to figure this out and tried out lots of solutions here on SO, but still can’t get through… seems like there needs to be something changed on my Nginx config, particularly for the blog/php location. Here’s my config:
After a ton of searching around, I finally found this solution.
Seems like the issue was that I needed to add a root to the app within “location /blog” and nest the “location
.php$” within /blog. Here’s my Nginx config that’s working now for a WordPress blog in a Rails app using Unicorn, in case anyone else needs it:
Ensure you have a types directive defined in your nginx config.
Maps file name extensions to MIME types of responses. Extensions are case-insensitive. Several extensions can be mapped to one type, for example: