ruby-on-rails - Rails/Nginx 不提供 JS 和 CSS

标签 ruby-on-rails nginx capistrano unicorn linode

我通过 Capistrano 部署了一个 Rails 3.2.8 应用程序,启用了 Assets 管道,到我的 Linode 服务器。

它正在运行 nginx + unicorn。

当我访问我的应用程序时,虽然 Assets 存在于 <RAILS_DIR>/public/assets 中,但没有提供最小化的 JS 和 CSS。 .

$ tree assets
assets
|-- application-66e477d6fd8cf088e8be44affeead089.css
|-- application-66e477d6fd8cf088e8be44affeead089.css.gz
|-- application-7d3ead38a0b5e276a97d48e52044ac31.js
|-- application-7d3ead38a0b5e276a97d48e52044ac31.js.gz

在我的应用程序中,我可以看到找不到那些确切的文件:

error

这是我的 nginx 配置:
server {
  listen 80 default deferred;
  server_name me.example.com;
  root /home/kennym/apps/app/current/public;

  location ^~ /assets/ {
    add_header Last-Modified "";
    add_header ETag "";
    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;
}

你能猜出什么问题吗?

最佳答案

location ^~ /assets/应该是 location ~ ^/assets/ .

前者不匹配/assets/,后者匹配以/assets/开头的模式

更新您的 nginx 配置以使缓存和预 gzipped 文件服务再次工作。

关于ruby-on-rails - Rails/Nginx 不提供 JS 和 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12657936/

相关文章:

ruby-on-rails - Rails 3. 无法在任何来源中找到 libv8-3.3.10.4

ruby-on-rails - Capistrano和Bundler问题- bundle : not found

ruby-on-rails - Gemfile.lock运行时不断变化 'rake spec'

ruby-on-rails - Rails 4 - 生产中需要的 javascript 运行时

ruby-on-rails - 嵌套属性未保存为 Mongoid 中的references_one

ruby-on-rails - Gem unf_ext 未能构建 gem native 扩展

ubuntu - "upstream prematurely closed connection while reading response header from upstream"Django、Ubuntu、Nginx、Gunicorn

javascript - 通过 JSON/AJAX 更新 HTML

nginx add_header Set-Cookie 过期不起作用

html - 使用 NGINX,css 文件不工作