django nginx安装问题
在下面的示例中,我尝试从配置 下面是我的conf文件,放在我的项目目录中,并在nginx目录的站点中链接了相同的文件 现在,当我访问我的应用程序时,我最终会遇到django nginx安装问题,django,nginx,Django,Nginx,在下面的示例中,我尝试从配置 下面是我的conf文件,放在我的项目目录中,并在nginx目录的站点中链接了相同的文件 现在,当我访问我的应用程序时,我最终会遇到502坏网关,nginx错误日志显示 2015/09/21 14:07:41[错误]8023#0:*7 connect()在连接到上游时失败(111:连接被拒绝),客户端:127.0.0.1,服务器:127.0.0.1,请求:“GET/HTTP/1.1”,上游:uwsgi://127.0.0.1:8001,主机:“127.0.0.1:80
502坏网关
,nginx错误日志显示
2015/09/21 14:07:41[错误]8023#0:*7 connect()在连接到上游时失败(111:连接被拒绝),客户端:127.0.0.1,服务器:127.0.0.1,请求:“GET/HTTP/1.1”,上游:uwsgi://127.0.0.1:8001,主机:“127.0.0.1:8000”
但是我可以访问这个链接,我在这里做错了什么,如何访问我的django应用程序
# mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 8000;
# the domain name it will serve for
server_name 127.0.0.1; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /home/rajeev/django-test/mysite/media; # your Django project's media files - amend as required
}
location /static {
#alias /path/to/your/mysite/static; # your Django project's static files - amend as required
alias /home/rajeev/django-test/mysite/static/; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /home/rajeev/django-test/mysite/conf/uwsgi_params; # the uwsgi_params file you installed
}
}
Edit1:uwsgi_参数文件
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param REQUEST_SCHEME $scheme;
uwsgi_param HTTPS $https if_not_empty;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
您在本教程中错过了一个。如果uWSGI不仅通过使用的端口工作,而且通过协议工作,则nginx的uWSGI配置不同于浏览器中的签入配置
为nginx部署uWSGI时,--http
应替换为--socket
。通过这种更改,nginx将正确理解来自uWSGI服务器的输出,但浏览器不会
浏览器配置(用于检查uWSGI是否工作)也可以用于nginx,但您必须在nginx中使用
proxy\u pass
而不是uWSGI\u pass
,并且不建议使用它,对于web服务器和uwsgi服务器之间的通信,uwsgi协议更快更好。显示uwsgi配置uwsgi的可能副本--套接字:8001--wsgi file test.py在哪里可以配置但我没有一个test.py文件要替换的是什么而不是这个djangowsgi.py
文件,位于yourproject/yourapp/
目录中。@GwynBleidD,我可能会迟到,但请您详细说明您的答案,我已经阅读了20多次,但您的答案中仍有一些东西难以理解,提前谢谢。