2012-01-31 3 views
3

난 레일 3.0 앱이 있는데, 트래픽이 많고 Nginx와 Unicorn의 조합을 통해 실행되는 앱입니다. 그 일은 유니콘과 그것의 노동자가 많은 자원을 소비한다는 것입니다. 그리고 내 앱의 성격으로 인해 데이터베이스에서 많은 레코드를 가져온 다음 데이터베이스 레코드로 생성 된 거의 정적 인 파일을 제공하는 것과 같습니다.유니콘이 아닌 nginx에서 캐시 된 루비 앱을 제공하는 방법은 무엇입니까?

이런 종류의 정적 파일을 생성하고 캐싱 할 수 있는지, 유니콘을 통해 앱 대신 nginx를 통해 1000 개 요청 후에 캐시를 다시로드하는 등의 리소스를 사용할 수 있는지 궁금 해서요

, 나는 많은 서버 설정을 모른다. 그래서 너희들이 나에게 조언을 해주기를 바란다.

감사합니다.

답변

3

난 당신이 난 그냥이 문제를 해결하고 여기에 내 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 { ... } 

내가 사용하고 레일의 조각입니다

나는 유니콘보다는의 nginx에서 내 고정 자산을 제공하려면 어떻게 을 의미 가정 3.0.10 그럼 내 대신에 ^/assets/ 같은 것이 필요할 것입니다. ~* 지시문은 nginx에게 민감한 reg-ex 비교 사례를 수행하도록 지시합니다. 또한 다른 언어에서와 마찬가지로 백 슬래시를 이스케이프 할 필요가 없습니다.

다음은 Nginx 설명서입니다. http://wiki.nginx.org/HttpCoreModule#location

관련 문제