2012-01-31 47 views
3

我有一個rails 3.0應用程序,它有很好的流量,它運行的應用程序通過Nginx和Unicorn的組合運行。事情是,獨角獸和它的工作人員消耗了大量的資源,並且由於我的應用程序的性質,從數據庫中提取了大量記錄,這就像提供幾乎與這些數據庫記錄一起生成的靜態文件一樣如何從nginx而不是獨角獸提供緩存的ruby應用程序?

I想知道是否可以生成這種靜態文件,緩存它們,通過nginx而不是通過獨角獸的應用程序來使用它們,以便在1000請求後使用更少的資源和類型的重新加載緩存

我開始研究有關,我不知道很多服務器配置,所以我希望你們對我有任何建議,這將是偉大的!

謝謝!

回答

3

我假定你的意思我如何爲我的靜態資產從nginx的,而不是獨角獸

我只是解決了這個問題,這裏是我的nginx.conf

# Prefer to serve static files directly from nginx to avoid unnecessary 
# data copies from the application server. 
try_files $uri/index.html $uri.html $uri @app; 

# Set Far Future Cache on Static Assets 
# All requests starting with /xyz/ where xyz is 
# one of the options below (~* == case insensitive) 
location ~* ^/(images|javascripts|stylesheets)/ { 
    # Per RFC2616 - 1 year maximum expiry 
    # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html 
    expires 1y; 
    add_header Cache-Control public; 

    # Some browsers still send conditional-GET requests if there's a 
    # Last-Modified header or an ETag header even if they haven't 
    # reached the expiry date sent in the Expires header. 
    add_header Last-Modified ""; 
    add_header ETag ""; 
    break; 
} 

location @app { ... } 

我使用Rails的一個片段3.0.10所以你需要像^/assets/這樣的東西。 ~*指令告訴nginx做一個不敏感的reg-ex比較。您也不需要像在其他語言中那樣避開反斜槓。

以下是關於此的Nginx文檔:http://wiki.nginx.org/HttpCoreModule#location

相關問題