我已经将准系统 Rails 部署到远程服务器,但是,它没有显示任何样式。如果我检查页面源,有一个指向样式表的链接(它使用 twitter bootstrap gem)
<link href="/assets/application-99190f98350e7ed3bb886d20f87bedfd.css" media="all" rel="stylesheet" />
但是当我点击链接时,我得到一个 404 Not Found
http://162.XXX.XXX/assets/application-99190f98350e7ed3bb886d20f87bedfd.css
404 Not Found
nginx/1.4.3
javascript 也是如此。
我在 ubuntu 服务器上使用 NGINX 和 Unicorn,根据 Ryan Bates 在他的 Railscasts“部署到 VPS” http://railscasts.com/episodes/335-deploying-to-a-vps?view=中描述的方式进行配置广播。如果我在远程服务器上查看 css 文件,它具有所有样式...
有谁知道问题可能是什么?如何在应用程序布局文件中指定样式表的完整路径?那会避免这个问题吗?
/*
=require twitter-bootstrap-static/bootstrap
Use Font Awesome icons (default)
To use Glyphicons sprites instead of Font Awesome, replace with "require twitter-bootstrap-static/sprites"
=require twitter-bootstrap-static/fontawesome
*/
html,
body {
height: 100%;
/* background-color: #;*/
/* The html and body elements cannot have any padding or margin. */
}
/* Wrapper for page content to push down footer */
#wrap {
min-height: 100%;
height: auto !important;
height: 100%;
/* Negative indent footer by it's height */
margin: 0 auto -60px;
}
/* Set the fixed height of the footer here */
#push,
#footer {
height: 60px;
}
#footer {
background-color: rgb(245, 240, 240);
}
/* Lastly, apply responsive CSS fixes as necessary */
@media (max-width: 767px) {
#footer {
margin-left: -20px;
margin-right: -20px;
padding-left: 20px;
padding-right: 20px;
}
}
#wrap > .container {
padding-top: 60px;
}
a:visited {
color: #000;
}
ul, menu, dir {
list-style-type: none;
更新
nginx.conf
upstream unicorn {
server unix:/tmp/unicorn.myapp.sock fail_timeout=0;
}
server {
listen 80 default deferred;
# server_name example.com;
root /home/michael/apps/myapp/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
应用程序.css
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require_tree .
*/