【问题标题】:uwsgi & Django with port 80uwsgi & Django 与端口 80
【发布时间】:2017-01-26 13:06:15
【问题描述】:

如果我使用uwsgi --ini kb_uwsgi.ini --http :80 运行 uwsgi,它会给我一个错误:

[uWSGI] getting INI configuration from kb_uwsgi.ini
*** Starting uWSGI 2.0.14 (64bit) on [Thu Jan 26 12:34:51 2017] ***
compiled with version: 5.4.0 20160609 on 06 January 2017 11:55:37
os: Linux-4.4.0-53-generic #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016
nodename: ip-172-31-16-133
machine: x86_64
clock source: unix
detected number of CPU cores: 4
current working directory: /home/ubuntu/webapps/kenyabuzz
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /home/ubuntu/webapps/kenyabuzz
your processes number limit is 64137
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
bind(): Permission denied [core/socket.c line 769]

如果我在命令前面加上sudo 或使用端口:8000 例如uwsgi --ini kb_uwsgi.ini --http :8000,则站点会加载

现在我尝试使用 nginx 和 uwsgi 使该站点运行,我得到 a 502 Bad Gateway nginx/1.10.0 (Ubuntu) nginx 工作正常,因为网站图标加载并且我可以使用 \static\... 访问静态文件我知道这是 Django 呈现问题。我也试过在不加载 djangoenv 的情况下加载 uwsgi --ini kb_uwsgi.ini --http :8000,它仍然加载。

kb_uwsgi.ini 文件如下所示:

# kb_uwsgi.ini file
[uwsgi]

# Django-related settings
# the base directory (full path)
chdir           = /home/ubuntu/webapps/kenyabuzz
# Django's wsgi file
module          = kb.wsgi
# the virtualenv (full path)
home            = /home/ubuntu/webapps/djangoenv

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 10
# the socket (use the full path to be safe
socket          = /tmp/kb.sock
# ... with appropriate permissions - may be needed
# chmod-socket    = 664
# clear environment on exit
vacuum          = true

kb_nginx.conf 一样

# kb.conf

# the upstream component nginx needs to connect to
upstream django {
    server unix:///tmp/kb.sock; # for a file socket
    #server 0.0.0.0: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      80;
    # the domain name it will serve for
    server_name kenyabuzz.nation.news; # 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/ubuntu/webapps/kenyabuzz/kb/media;  # your Django project's media files - amend as required
    }

    location /static {
        alias /home/ubuntu/webapps/kenyabuzz/kb/static; # your Django project's static files - amend as required
    }

    location /favicon.ico {
        alias /home/ubuntu/webapps/kenyabuzz/kb/static/kb/favicon.ico; # favicon
    }

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

日志有:

2017/01/26 13:02:17 [crit] 4065#4065: *10 connect() to unix:///tmp/kb.sock failed (2: No such file or directory) while connecting to upstream, client: 197.232.12.165, server: kenyabuzz.nation.news, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///tmp/kb.sock:", host: "kenyabuzz.nation.news"

uwsgi 应该自动创建文件(确实如此),并在使用上面的示例关闭文件时将其删除。

感谢您对此的任何帮助。

更新

编辑 .ini 文件并取消注释掉 chmod-socket=664 重新启动 nginx 时仍然没有创建 kb.sock 文件。

【问题讨论】:

  • 当你明确告诉 uwsgi 在 http 端口(即端口 8000)上服务时,我不明白你为什么要尝试使用套接字。
  • 我正在使用套接字进行测试,以确保站点配置正确并通过 uwsgi 提供服务。现在我将 nginx 设置为使用端口 80 服务并检查域并得到提到的错误。额外的套接字测试和端口,即使用 http :80 试图确定端口 80 是否可能无法工作/可用。
  • 所以请显示您实际用于启动uwsgi的命令。

标签: django uwsgi


【解决方案1】:

对于 nginx:

# kb.conf
...
# the upstream component nginx needs to connect to
upstream django {
    server unix:/tmp/kb.sock;
}
...

对于 uWSGI:

# kb_uwsgi.ini file
[uwsgi]
...
# the socket (use the full path to be safe
socket          = /tmp/kb.sock
chmod-socket    = 666
...

【讨论】:

  • 试过了,现在日志显示2017/01/27 07:23:04 [error] 8639#8639: *1 connect() to unix:/tmp/kb.sock failed (111: Connection refused) while connecting to upstream, client: 197.232.12.165, server: kenyabuzz.nation.news, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/kb.sock:", host: "kenyabuzz.nation.news"
  • 我想我需要编辑听 0.0.0.0 或 127.0.0.1:8000 或 80
  • 切换到监听0.0.0.0:80静态加载但错误日志是一样的。
  • 您的/home/ubuntu/webapps/kenyabuzz/uwsgi_params 中有什么内容?
猜你喜欢
  • 2021-05-06
  • 2013-03-19
  • 2010-12-02
  • 2013-10-14
  • 1970-01-01
  • 2011-11-25
  • 2021-06-05
  • 1970-01-01
  • 2020-12-30
相关资源
最近更新 更多