Reputation:
I delppoyed Django web application used nginx+gunicorn+supervisor.It works well. But when I try to add new post with picture in django admin I get a 405 error. On developer server worked fine. My nginx config below:
upstream app_server {
server unix:/tmp/PMC.sock fail_timeout=0;
}
server {
listen 80;
server_name site.ru;
access_log /home/venv/PMC/logs/nginx-access.log main;
error_log /home/venv/PMC/logs/nginx-error.log debug;
location /static/ {
alias /home/venv/PMC/static/;
access_log off;
}
location /media/ {
alias /home/venv/PMC/media/;
access_log off;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://app_server;
break;
}
}
}
Upvotes: 1
Views: 1405
Reputation: 6341
Error 405 is "Method not allowed", which means that either at Nginx level or using a view decorator you allowed only certain methods, i.e. only GET
or safe methods
, and probably not POST
. Therefore when 'getting' the page it's ok, but when 'posting' it back you get 405 error.
Note: Nginx has special command try_files
instead of if(!-f ...)
. It's better to use it, as it offers much better performance and a little more secure.
Upvotes: 1