Nginx托管了uwsgi django app:只能通过curl访问,而不能通过浏览器访问

时间:2017-07-13 19:00:51

标签: django nginx uwsgi

我正在使用uwsgi和nginx托管一个Django应用程序。

如果我拨打curl -v my_ip:port,则会连接。如果我将浏览器指向my_ip:port,则会返回ERR_CONNECTION_REFUSED,并且连接不会显示在日志中。

uWSGI:

档案:data_collection_project.ini

[uwsgi]
project = data_collection_project
base = /data_nfs/data_collection_project

chdir = %(base)
# /%(project)
home = /home/rootadmin/.virtualenvs/data_collection
#plugins = python

#module = data_collection_project.wsgi:application
module = data_collection_project.wsgi:application
master = true
processes = 2


socket = %(base)/%(project).sock
chmod-socket = 666

nginx的: 档案:/etc/nginx/sites-available

# mysite_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
        server unix:///data_nfs/data_collection_project/data_collection_project.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      8433;
    # the domain name it will serve for
    server_name my_ip; # 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 /data_nfs/data_collection_project/media;  # your Django project's media files - amend as requir$    }

    location /static {
        alias /data_nfs/data_collection_project/static; # your Django project's static files - amend as requi$    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /data_nfs/data_collection_project/uwsgi_params; # the uwsgi_params file you installed
    }
}

根据我的理解,这应该使网站可以通过my_ip用于外部浏览器,但事实并非如此。我不明白为什么。我错过了什么?

编辑:如果我关闭uwsgi然后尝试拨打ip:port,则会在/var/log/nginx/error.log connect () to unix:///...sock failed. (111:connection refused)添加错误日志此错误有道理,因为uwsgi没有处理套接字。这似乎意味着nginx正在工作,并且当我执行curl my_ip:port时确实将请求传递给套接字?

1 个答案:

答案 0 :(得分:1)

我不是100%肯定,但根据您的编辑,似乎nginx正确传递。也许Django' ALLOWED_HOSTS?我按照以下步骤操作:

  1. 确保data_collection_project.ini是使用过的那个(可能是尝试命令行参数而不是ini文件作为测试之一)。
  2. deamonize添加到data_collection_project.ini以使uwsgi登录到文件。
  3. 检查Django是否没有断开连接。