在我的項目中有一個問題。不要上傳文件。這裏是我的代碼不要通過nginx上傳文件幫助上傳模塊
配置nginx的
server{
listen 9000;
server_name localhost;
root /home/path/my/project;
location ~ ^/(static|media)/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
}
location /file-upload {
internal;
upload_pass /upload-file/;
upload_store /home/payh/my/project/media/video;
upload_max_file_size 250m;
upload_set_form_field $upload_field_name.name "$upload_file_name";
upload_set_form_field $upload_field_name.content_type "$upload_content_type";
upload_set_form_field $upload_field_name.path "$upload_tmp_path";
upload_pass_form_field "^csrfmiddlewaretoken$";
upload_limit_rate 2m;
track_uploads upload 1m;
}
location = /upload/progress {
report_uploads upload;
}
location/{
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 10;
proxy_read_timeout 10;
proxy_pass http://localhost:8000/;
}
error_page 500 502 503 504 /media/50x.html;
}
請點擊按鈕上傳後nginx_accel進來功能。然後查看爲nginx創建響應併發送它。不允許Nginx返回405。我不知道爲什麼。 我views.py
@login_required
@csrf_protect
def upload(request):
context = RequestContext(request)
if request.method == 'POST':
pathfile = request.POST.get('upfile.path')
upfile = open(pathfile, 'r')
file = File(upfile)
form = NewFileForm(request.POST, initial={'upfile':file})
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse(upload))
else:
form = NewFileForm()
return render_to_response('upload.html',
{'form':form},
context_instance=context)
@login_required
@csrf_protect
def nginx_accel(request):
if request.user.id == 1:
file = request.FILES.get('upfile').name
url = '/'.join(['/file-upload', file])
response = HttpResponse()
response['Content-Type']= ''
response['X-Accel-Redirect'] = url
return response
Nginx的瀏覽器返回 「405不允許」。誰能說爲什麼會出現這個問題?