为什么没有为 uwsgi 生成 .sock 文件?

为什么没有为 uwsgi 生成 .sock 文件?

在过去的 6 个小时里,我已经撞了头了,但似乎没有什么对我有用。

我正在尝试通过 nginx 和 uwsgi 托管 Django。根据我的理解和研究,我配置了 nginx.conf 和 uwsgi.ini 文件。

nginx.conf

# mysite_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
    server unix:/tmp/abc.sock; # for a file socket
}

# configuration of the server
server {
    # the port your site will be served on
    listen      80;
    # the domain name it will serve for
    server_name localhost; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 2048M;   # adjust to taste

    # Django media
    location /media  {
        alias /<path_to>/media;  # your Django project's media files - amend as required
    }

    location /static {
        alias /<path_to>/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        include     /<path_to>/uwsgi_params; # the uwsgi_params file you installed
        uwsgi_param REMOTE_USER $remote_user;
        uwsgi_param DATE_GMT $date_gmt;
        uwsgi_param DATE_LOCAL $date_local;
        uwsgi_param AUTH_TYPE Basic;
        uwsgi_read_timeout 600s;
        uwsgi_pass  django;
    }
}

uwsgi.ini

[uwsgi]

# Django-related settings
# the base directory (full path)
chdir           = <path_to>/site
# Django's wsgi file
module          = pjgweb.wsgi:application
# the virtualenv (full path)
home            = /<path_to>/ENV

# process-related settings
# gid
gid             = www-data
# uid
uid             = www-data
# master
master          = true
# maximum number of worker processes
processes       = 6
# maximum number of threads for each worker process
threads         = 5
# the socket (use the full path to be safe
socket          = /tmp/abc.sock
# ... with appropriate permissions - may be needed
chmod-socket    = 666
# clear environment on exit
vacuum          = true
thread_lock     = true
python_thread   = true
# set the DJANGO MODULE SETTINGS
env             = DJANGO_SETTINGS_MODULE=pjintegweb.settings_production
# Log to
logto           = /<path_to>/uwsgi-app.log
# Statistics
stats           = :9191
stats-http      = true
  • 我还为 nginx.conf 和 uwsgi.ini 创建了符号链接。

  • 我确实为 systemd 配置了emperor.uwsgi.service 文件

      [Unit]
      Description=uWSGI Emperor service
      After=syslog.target
    
      [Service]
      ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals --uid www-data --gid www-data
      Restart=always
      KillSignal=SIGQUIT
      Type=notify
      StandardError=syslog
      NotifyAccess=all
    
      [Install]
      WantedBy=multi-user.target
    

当我检查 nginx 日志文件时,我看到下面的内容

: x.x.x.x, server: x.x.x.x, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/run/uwsgi/abc.sock:", host: "x.x.x.x"
2021/06/09 16:05:37 [crit] 1949#1949: *1 connect() to unix:/run/uwsgi/abc.sock failed (2: No such file or directory) while connecting to upstream, client: x.x.x.x, server: x.x.x.x, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/run/uwsgi/abc.sock:", host: "x.x.x.x"
2021/06/09 16:05:37 [crit] 1949#1949: *1 connect() to unix:/run/uwsgi/abc.sock failed (2: No such file or directory) while connecting to upstream, client: x.x.x.x, server: x.x.x.x, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/run/uwsgi/abc.sock:", host: "x.x.x.x"
2021/06/09 16:39:04 [alert] 2890#2890: *1 open socket #21 left in connection 3
2021/06/09 16:39:04 [alert] 2890#2890: *2 open socket #22 left in connection 4
2021/06/09 16:39:04 [alert] 2890#2890: aborting

uwsgi日志

bind(): No such file or directory [core/socket.c line 230]
*** Starting uWSGI 2.0.19.1 (64bit) on [Wed Jun  9 18:48:43 2021] ***
compiled with version: 7.5.0 on 02 June 2021 07:22:38
os: Linux-5.4.0-42-generic #46~18.04.1-Ubuntu SMP Fri Jul 10 07:21:24 UTC 2020
machine: x86_64
clock source: unix
detected number of CPU cores: 12
current working directory: /<path_to>
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /<path_to>
your processes number limit is 127942
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)
uwsgi socket 0 bound to UNIX address /tmp/abc.sock fd 3
Python version: 3.6.9 (default, Jan 26 2021, 15:33:00)  [GCC 8.4.0]
PEP 405 virtualenv detected: /<path_to>/ENV
Set PythonHome to /<path_to>/ENV
Python main interpreter initialized at 0x55cc047f50c0
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 802648 bytes (783 KB) for 30 cores
*** Operational MODE: preforking+threaded ***

WSGI app 0 (mountpoint='') ready in 2 seconds on interpreter 0x55cc047f50c0 pid: 2828 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 2828)
spawned uWSGI worker 1 (pid: 2833, cores: 5)
spawned uWSGI worker 2 (pid: 2834, cores: 5)
spawned uWSGI worker 3 (pid: 2835, cores: 5)
spawned uWSGI worker 4 (pid: 2840, cores: 5)
spawned uWSGI worker 5 (pid: 2845, cores: 5)
spawned uWSGI worker 6 (pid: 2850, cores: 5)
*** Stats server enabled on :9191 fd: 21 ***
SIGINT/SIGQUIT received...killing workers...
worker 1 buried after 1 seconds
worker 2 buried after 1 seconds
worker 3 buried after 1 seconds
worker 4 buried after 1 seconds
worker 5 buried after 1 seconds
worker 6 buried after 1 seconds
goodbye to uWSGI.
VACUUM: unix socket /tmp/abc.sock removed.
  • 当我执行以下命令时,我没有看到任何错误,但它永远不会返回到命令行。不知道为什么

    uwsgi --ini uwsgi.ini [uWSGI] 从 /path_to/uwsgi.ini 获取 INI 配置

它永远留在那里。我在互联网上看到了很多帖子,但似乎没有一个对我有帮助。请帮忙。谢谢。

新日志:

--- no python application found, check your startup logs for errors ---
[pid: 9219|app: -1|req: -1/1] x.x.x.x () {38 vars in 707 bytes} [Thu Jun 10 09:26:20 2021] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)

相关内容