我想用nginx和gunicorn部署我的django 1.6版本项目。在我的服务器,我将自己的项目nginx的文件:django运行gunicorn和nginx:400不好的请求
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
上运行一个卷曲时,我得到<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停留不动,好像没有请求发送给它。
任何想法?
UPDATE: 我运行gunicor:gunicorn myproject.wsgi -b localhost:8333
的curl localhost
返回我的静态/ 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"
'警告:该命令是deprecated.'我以为这只是depreacated因而起作用。否则,它会是和错误消息 – smarber 2014-10-18 12:44:43
@smarber你应该尝试使用siply'gunicorn'来运行这个。 – 2014-10-18 12:47:16
我更新了我的问题 – smarber 2014-10-18 13:04:10