2013-10-12 3 views
10

send_file을 사용하는 컨트롤러의 메소드로 이동하는 다운로드 링크가있어서 파일 이름을 uuid로 바꾼다. 링크를 클릭하면 NGINX 로그와 레일즈 로그에 요청이 표시되지만 다운로드가 시작되기까지 최대 90 초가 소요됩니다. proxy_buffers 및 클라이언트 _ * _ 버퍼를 사용하여 다양한 설정을 시도했지만 아무런 영향을 미치지 않았습니다. 파일의 실제 URL을 사용하는 HTML5 오디오 플레이어가 있으며 지연없이 즉시 파일을 스트리밍합니다.NGINX 다운로드 속도가 느리다. send_file로 시작한다.

내의 nginx의 구성 :

upstream app { 
    server unix:/home/archives/app/tmp/unicorn.sock fail_timeout=0; 
} 

server { 
    listen  80 default deferred; 
    server_name archives.example.com; 
    root  /home/archives/app/public/; 

    client_max_body_size 200M; 
    client_body_buffer_size 100M; 
    proxy_buffers 2 100M; 
    proxy_buffer_size 100M; 
    proxy_busy_buffers_size 100M; 

    try_files /maintenance.html $uri/index.html $uri.html $uri @production; 

    location @production { 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_set_header X-Sendfile-Type X-Accel-Redirect; 
    proxy_set_header X-Accel-Mapping /home/archives/app/public/uploads/audio/=/uploads/audio/; 
    proxy_redirect off; 
    proxy_pass http://app; 
    } 

    location ~ "^/assets/*" { 
    gzip_static on; 
    expires  max; 
    add_header Cache-Control public; 
    } 

    location ~ (?:/\..*|~)$ { 
    access_log off; 
    log_not_found off; 
    deny all; 
    } 

    error_page 500 502 503 504 /500.html; 
    location = /500.html { 
    root /home/archives/app/public; 
    } 
} 

레일 컨트롤러 :

def download 
    send_file @audio.path, type: @audio_content_type, filename: "#{@audio.title} - #{@audio.speaker.name}" 
end 
+0

환경 설정에서 'config.action_dispatch.x_sendfile_header ='X-Accel-Redirect 'NGINX 용 #'이 (가) 주석 처리 되었습니까? – hamitron

+0

공용 폴더에서 mp3를 이동하는 경우 성능을 테스트하기 위해 브라우저를 통해 직접 액세스 할 수 있습니다 (컨트롤러 논리 무시). 여전히 NGINX 설정 문제 일 가능성이 있습니다. 또한 webbrick (레일 s -b 0.0.0.0)을 사용하여 응용 프로그램을 실행 해보십시오. 차이가 있는지 확인하십시오. – Roger

답변

0

테스트를 마친 후 문제를 일으키는 터보 링크라고 알았습니다. 백그라운드에서 XHR 요청을 수행하여 파일을 먼저 다운로드 한 다음 브라우저가 실제로 파일을 다운로드 할 수있게했습니다. 'data-no-turbolink'= 'true'를 내 링크에 추가하면 파일이 즉시 다운로드됩니다.

0

당신이 지나치게 큰 프록시 버퍼를 설정했기 때문에 아마 속도가 느린? 100M 프록시 버퍼는 서버가 원본 데이터를 대상으로 보내기 전에 100M을 다운로드한다는 것을 의미합니다. 기본값은 32kB이고 512kB와 같은 값은 이미 좋은 숫자입니다.

관련 문제