简体   繁体   English

使用gunicorn和nginx运行的django:400错误的请求

[英]django running with gunicorn and nginx: 400 bad request

I'm trying to deploy my django version 1.6 project using nginx and gunicorn. 我正在尝试使用nginx和gunicorn部署Django 1.6版项目。 In my server, I added my project nginx file: 在我的服务器中,添加了我的项目nginx文件:

error_log /var/log/nginx/myproject-error.log;
access_log /var/log/nginx/myproject-access.log;
server {
       listen 80;
       server_name <domain_name>;
       root <path_to_my_root_project>;

       location /static/ {
           root <path_to_my_root_project>;
           expires max;
           add_header Pragma public;
          add_header Cache-Control "public, must-revalidate, proxy-revalidate";
      }

      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-Schema $scheme;
          proxy_connect_timeout 10;
          proxy_read_timeout 10;

          proxy_pass http://localhost:8333/;
      }
      error_page 500 502 503 504 /static/50x.html;
}

In my django settings file, I set static paths: 在我的django设置文件中,我设置了静态路径:

# Static
STATIC_ROOT = BASE_DIR + '/static'
STATIC_URL = '/static/'

And the I run gunicorn as following: 我以如下方式运行gunicorn:

$ gunicorn_django -b localhost:8333
!!!
!!! WARNING: This command is deprecated.
!!!
!!!     You should now run your application with the WSGI interface
!!!     installed with your project. Ex.:
!!!
!!!         gunicorn myproject.wsgi:application
!!!
!!!     See https://docs.djangoproject.com/en/1.5/howto/deployment/wsgi/gunicorn/
!!!     for more info.
!!!

So when I run a curl on my server curl localhost , I get <h1>Bad Request (400)</h1> and the logs don't say much further than 127.0.0.1 - - [18/Oct/2014:14:38:57 +0200] "GET / HTTP/1.1" 400 37 "-" "curl/7.26.0" 因此,当我在服务器curl localhost上运行curl时,我收到<h1>Bad Request (400)</h1> ,并且日志说的不比127.0.0.1 - - [18/Oct/2014:14:38:57 +0200] "GET / HTTP/1.1" 400 37 "-" "curl/7.26.0"

And gunicorn stays still, as if no request is sent to it. 而且,gunicorn保持静止,好像没有请求发送给它。

Any ideas? 有任何想法吗?

UPDATE: I run gunicor: gunicorn myproject.wsgi -b localhost:8333 The curl localhost returns my static/50x.html error page. 更新:我运行gunicor: gunicorn myproject.wsgi -b localhost:8333 curl localhost返回我的static / 50x.html错误页面。 And I got this in nginx logs: 我在nginx日志中得到了这个:

2014/10/18 15:06:31 [error] 16037#0: *32 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: servername.local.fr, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8333/", host: "localhost"

This one tells you what to do. 这个告诉你该怎么做。

!!!     You should now run your application with the WSGI interface
!!!     installed with your project. Ex.:
!!!
!!!         gunicorn myproject.wsgi:application

NGINX is working fine, the gunicorn just isn't receiving your request. NGINX运作良好,刚收到您的要求。

Just to to your project dir and run gunicorn with proper parameters as described here: http://docs.gunicorn.org/en/latest/run.html#gunicorn-django 只需转到您的项目目录并使用此处描述的适当参数运行gunicorn: http ://docs.gunicorn.org/en/latest/run.html#gunicorn-django

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM