2012-09-30 37 views
3

我通过启用资产管道的Capistrano部署了一个Rails 3.2.8应用程序到我的Linode服务器。未提供JS和CSS的Rails/Nginx

它运行nginx +独角兽。

当我访问我的应用程序时,虽然资产存在于<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; 
} 

你能猜到是什么错误?

回答

6

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

前者是不匹配/资产/,后者是与/资产开始的图形/

更新你的nginx的配置可以让服务工作再次缓存和预gzip压缩的文件相匹配。

+0

感谢您发现这个错字 - 它现在可以正常工作。 :-) –

2

我通过注释nginx.conf中的location ^~ /assets/块来解决这个问题。

+2

只有当你想要rails服务器来处理静态文件而不是nginx时,这是可以的。如果这只是你正在使用它的那种,那么nginx的目的就会失败。 –

+0

同意...这是一种黑客。 –

0

对于那些有同样问题的人,对我来说,解决方案是进入/etc/nginx/conf.d/default.conf并正确设置root字段。

相关问题