2014-11-25 4 views
0

Nginx 업로드 모듈을 Rails 백엔드 서버와 통합하려고합니다. 다음은 내 서버 구성입니다.Nginx 업로드 모듈이 출력 파일을 생성하지 못했습니다.

upstream dev_app { 
    server 127.0.0.1:3000; 
} 

server { 
    listen [::]:8081 ipv6only=on; 

    server_name _; 

    root  /Users/me/workspace/dev_app/public; 
    index index.html; 

    try_files $uri $uri/index.html $uri.html @dev_app; 

    client_max_body_size 512M; 
    client_body_buffer_size 2048K; 

    location /v2/photos/avatar { 
    upload_pass /v2/_photos/avatar; 
    upload_store /tmp/uploads 1; 
    upload_state_store /tmp/upload_state; 
    upload_resumable on; 
    upload_store_access user:rw group:rw all:r; 
    upload_max_file_size 512M; 

    # form fields to be passed to Rails 
    upload_set_form_field $upload_field_name.filename "$upload_file_name"; 
    upload_set_form_field $upload_field_name.path "$upload_tmp_path"; 
    upload_set_form_field $upload_field_name.content_type "$upload_content_type"; 
    upload_pass_form_field "^photo$"; 
    upload_cleanup 400 404 499 500-505; 
    } 

    location @dev_app { 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_redirect off; 

    proxy_pass http://dev_app; 
    } 
} 

그러나 파일을 업로드하려고하면 항상 오류가 발생합니다.

curl -v --form [email protected] http://localhost:8081/v2/photos/avatar 
* Hostname was NOT found in DNS cache 
* Trying ::1... 
* Connected to localhost (::1) port 8081 (#0) 
> POST /v2/photos/avatar HTTP/1.1 
> User-Agent: curl/7.37.1 
> Host: localhost:8081 
> Accept: */* 
> Content-Length: 6399 
> Expect: 100-continue 
> Content-Type: multipart/form-data; boundary=------------------------0bef04705a84fc2f 
> 
< HTTP/1.1 100 Continue 
< HTTP/1.1 503 Service Temporarily Unavailable 
* Server nginx is not blacklisted 
< Server: nginx 
< Date: Tue, 25 Nov 2014 20:44:05 GMT 
< Content-Type: text/html 
< Content-Length: 206 
< Connection: keep-alive 
* HTTP error before end of send, stop sending 
< 
<html> 
<head><title>503 Service Temporarily Unavailable</title></head> 
<body bgcolor="white"> 
<center><h1>503 Service Temporarily Unavailable</h1></center> 
<hr><center>nginx</center> 
</body> 
</html> 
* Closing connection 0 

Nginx의 오류 로그 :

2014/11/26 03:44:05 [error] 75010#0: *88 failed to create output file "/tmp/uploads/0/0000000007" for "photo.jpg" (2: No such file or directory), client: ::1, server: _, request: "POST /v2/photos/avatar HTTP/1.1", host: "localhost:8081" 

내 Nginx의 버전은 1.6.2이다.

내가 잘못 했나요?

답변

0

마지막으로, Nginx 업로드 모듈이 폴더를 자동으로 만들지 않기 때문에 알아 냈습니다. 수동으로 임시 폴더를 만들어야합니다. 지시문 upload_store /tmp/uploads 1;을 사용하면 /tmp/uploads/0/00000009, /tmp/uploads/1/000000001 등의 경로가 생성됩니다.

스크립트로 쉽게 구현할 수 있습니다. 좋아하는 것 :

ruby -e 'require "fileutils"; (0..9).each{|i| FileUtils.mkdir_p("/tmp/uploads/#{i}") rescue nil }' 
관련 문제