2012-01-04 46 views
2

我正在使用Rails 3.1資產管道,它使用自定義來源Cloudfront CDN提供服務。nginx + Rails 3.1 + Cloudfront資產子目錄404丟失

這是我已經寫在我的nginx.conf服務於資產gzip和緩存:

   location ^~ /assets/ { 
        allow all; 
        gzip_http_version 1.0; 
        gzip_static on; 
        expires 365d; 
        add_header Last-Modified ""; 
        add_header ETAg ""; 
        add_header Cache-Control public; 
      } 

的問題是,例如子目錄/ background /在我的圖片資源文件夾中,它們的項目缺少404s。

當我禁用上面的nginx位置配置問題消失。如何正確配置nginx來爲子目錄中的資源提供服務?

感謝

+0

你有沒有想出解決辦法? – NudeCanalTroll 2012-04-19 03:08:18

+0

抱歉需要一段時間才能回來。但是,我今天試了一下,效果很好!謝啦。 – davicta 2012-04-25 06:58:16

回答

1

這爲我工作:

location ~ ^/(assets)/  { 
    root /opt/appname/public; # or whatever the path is to your app's public folder 
    gzip_http_version 1.0; 
    gzip_static on; 
    access_log off; 
    expires 1y; 
    add_header Cache-Control public; 
    add_header Last-Modified ""; 
    add_header ETag ""; 
    break; 
}