[英]Bad Request (400) Nginx + Gunicorn + Django + FreeBSD
[英]django running with gunicorn and nginx: 400 bad request
我正在嘗試使用nginx和gunicorn部署Django 1.6版項目。 在我的服務器中,添加了我的項目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;
}
在我的django設置文件中,我設置了靜態路徑:
# Static
STATIC_ROOT = BASE_DIR + '/static'
STATIC_URL = '/static/'
我以如下方式運行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.
!!!
因此,當我在服務器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"
而且,gunicorn保持靜止,好像沒有請求發送給它。
有任何想法嗎?
更新:我運行gunicor: gunicorn myproject.wsgi -b localhost:8333
curl localhost
返回我的static / 50x.html錯誤頁面。 我在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"
這個告訴你該怎么做。
!!! You should now run your application with the WSGI interface
!!! installed with your project. Ex.:
!!!
!!! gunicorn myproject.wsgi:application
NGINX運作良好,剛收到您的要求。
只需轉到您的項目目錄並使用此處描述的適當參數運行gunicorn: http ://docs.gunicorn.org/en/latest/run.html#gunicorn-django
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.