在本地运行生产模式的Rails应用程序

5

我正在尝试使用以下命令在生产模式下运行Rails(不太了解它):

rails server -e production

但是我在控制台上得到了这些错误,并且加载了一个没有 CSS 样式的丑陋页面:
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://10.20.200.199:3000/".
(index):1 Refused to execute script from 'http://10.20.200.199:3000/javascripts/application.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
(index):1 Refused to execute script from 'http://10.20.200.199:3000/logins/plugins.js?v=1' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

这种情况出现在我们使用的所有脚本中。
有人能帮我看看这里可能出了什么问题吗?
先行致谢。
1个回答

4

为了在生产环境下运行预构建资源,请使用以下命令:rake assets:precompile

上述错误表明浏览器请求静态资源;这些资源没有被构建(在生产环境中不会自动构建 - 每次部署时都需要构建它们),因此在其URL上找不到任何内容,只能呈现错误页面。因此,浏览器错误地表示下载的CSS和JavaScript文件具有错误的MIME类型。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接