【问题标题】:uwsgi failed to open python file /root/ ... /wsgi.py (DJANGO)uwsgi 无法打开 python 文件 /root/ ... /wsgi.py (DJANGO)
【发布时间】:2022-01-11 15:02:49
【问题描述】:

/var/log/uwsgi/myapp.log:

Tue Jan 11 15:27:45 2022 - *** Starting uWSGI 2.0.18-debian (64bit) on [Tue Jan 11 15:27:45 2022] ***

Tue Jan 11 15:27:45 2022 - compiled with version: 10.0.1 20200405 (experimental) [master revision 0be9efad938:fcb98e4978a:705510a708d3642c9c962beb663c476167e4e8a4] on 11 April 2020 11:15:55
Tue Jan 11 15:27:45 2022 - os: Linux-5.4.0-92-generic #103-Ubuntu SMP Fri Nov 26 16:13:00 UTC 2021
Tue Jan 11 15:27:45 2022 - nodename: 185-46-8-164.cloudvps.regruhosting.ru
Tue Jan 11 15:27:45 2022 - machine: x86_64
Tue Jan 11 15:27:45 2022 - clock source: unix
Tue Jan 11 15:27:45 2022 - pcre jit disabled
Tue Jan 11 15:27:45 2022 - detected number of CPU cores: 1
Tue Jan 11 15:27:45 2022 - current working directory: /
Tue Jan 11 15:27:45 2022 - detected binary path: /usr/bin/uwsgi-core
Tue Jan 11 15:27:45 2022 - chdir() to /root/eva/lawyer
Tue Jan 11 15:27:45 2022 - chdir(): Permission denied [core/uwsgi.c line 2623]
Tue Jan 11 15:27:45 2022 - VACUUM: pidfile removed.
Tue Jan 11 15:27:45 2022 - chdir(): Permission denied [core/uwsgi.c line 1647]
Tue Jan 11 15:27:45 2022 - *** Starting uWSGI 2.0.18-debian (64bit) on [Tue Jan 11 15:27:45 2022] ***
Tue Jan 11 15:27:45 2022 - compiled with version: 10.0.1 20200405 (experimental) [master revision 0be9efad938:fcb98e4978a:705510a708d3642c9c962beb663c476167e4e8a4] on 11 April 2020 11:15:55
Tue Jan 11 15:27:45 2022 - os: Linux-5.4.0-92-generic #103-Ubuntu SMP Fri Nov 26 16:13:00 UTC 2021
Tue Jan 11 15:27:45 2022 - nodename: 185-46-8-164.cloudvps.regruhosting.ru
Tue Jan 11 15:27:45 2022 - machine: x86_64
Tue Jan 11 15:27:45 2022 - clock source: unix
Tue Jan 11 15:27:45 2022 - pcre jit disabled
Tue Jan 11 15:27:45 2022 - detected number of CPU cores: 1
Tue Jan 11 15:27:45 2022 - current working directory: /
Tue Jan 11 15:27:45 2022 - writing pidfile to /run/uwsgi/app/myapp/pid
Tue Jan 11 15:27:45 2022 - detected binary path: /usr/bin/uwsgi-core
Tue Jan 11 15:27:45 2022 - chdir() to /root/eva/lawyer
Tue Jan 11 15:27:45 2022 - your processes number limit is 1831
Tue Jan 11 15:27:45 2022 - your memory page size is 4096 bytes
Tue Jan 11 15:27:45 2022 - detected max file descriptor number: 1024
Tue Jan 11 15:27:45 2022 - lock engine: pthread robust mutexes
Tue Jan 11 15:27:45 2022 - thunder lock: disabled (you can enable it with --thunder-lock)
Tue Jan 11 15:27:45 2022 - uwsgi socket 0 bound to UNIX address /run/uwsgi/app/myapp/socket fd 3
Tue Jan 11 15:27:45 2022 - setgid() to 33
Tue Jan 11 15:27:45 2022 - setuid() to 33
Tue Jan 11 15:27:45 2022 - Python version: 3.8.10 (default, Nov 26 2021, 20:14:08)  [GCC 9.3.0]
Tue Jan 11 15:27:45 2022 - Python main interpreter initialized at 0x55ae4c9e8c70
Tue Jan 11 15:27:45 2022 - python threads support enabled
Tue Jan 11 15:27:45 2022 - your server socket listen backlog is limited to 100 connections
Tue Jan 11 15:27:45 2022 - your mercy for graceful operations on workers is 60 seconds
Tue Jan 11 15:27:45 2022 - mapped 500256 bytes (488 KB) for 10 cores
Tue Jan 11 15:27:45 2022 - *** Operational MODE: preforking+threaded ***
Tue Jan 11 15:27:45 2022 - added /root/eva/venv/lib/python3.8/site-packages/ to pythonpath.
Tue Jan 11 15:27:45 2022 - failed to open python file /root/eva/lawyer/lawyer/wsgi.py

Tue Jan 11 15:27:45 2022 - unable to load app 0 (mountpoint='') (callable not found or import error)
Tue Jan 11 15:27:45 2022 - *** no app loaded. going in full dynamic mode ***
Tue Jan 11 15:27:45 2022 - *** uWSGI is running in multiple interpreter mode ***
Tue Jan 11 15:27:45 2022 - spawned uWSGI master process (pid: 28754)
Tue Jan 11 15:27:45 2022 - spawned uWSGI worker 1 (pid: 28759, cores: 2)
Tue Jan 11 15:27:45 2022 - spawned uWSGI worker 2 (pid: 28760, cores: 2)
Tue Jan 11 15:27:45 2022 - spawned uWSGI worker 3 (pid: 28761, cores: 2)
Tue Jan 11 15:27:45 2022 - spawned uWSGI worker 4 (pid: 28762, cores: 2)
Tue Jan 11 15:27:45 2022 - spawned uWSGI worker 5 (pid: 28763, cores: 2)

我不明白错误的原因:Tue Jan 11 15:27:45 2022 - failed to open python file /root/eva/lawyer/lawyer/wsgi.py 我不明白为什么 uwsgi 不能t 打开这个 python 文件。通往它的道路是正确的

myapp.ini:

[uwsgi]
chdir = /root/eva/lawyer
env = DJANGO_SETTINGS_MODULE= lawyer.settings
wsgi-file = /root/eva/lawyer/lawyer/wsgi.py
#module = lawyer.uwsgi:application
workers = 1
max-requests = 5000
#plugins-dir=/usr/lib/uwsgi/plugins/
plugins = python3
#virtualenv = /root/eva/venv
pythonpath = /root/eva/venv/lib/python3.8/site-packages
processes = 5
threads = 2
master = true
die-on-term = true
socket = /run/uwsgi/app/myapp/socket
chmod-socket = 666
vacuum = true
uid = www-data
gui = www-data

请告诉我,错误的原因可能是什么以及如何解决? 这似乎是一个很容易解决的问题。但是我在互联网上找不到有关它的信息

【问题讨论】:

  • uwsgi 以用户 'www-data' 的身份运行是 wsgi 文件和父目录设置是否具有正确的权限,以便用户可以读取它?
  • 我不确定。告诉我,我该如何检查这个?如何授予访问权限?
  • 您可以在您的目录中运行ls -la 以确认文件所有者和组权限。出于测试的目的,我会将您的 Django 目录中的所有内容设置为可通过运行 www-data 访问 chown -R www-data:www-data ./* 可能更好的文件位置将在 /var/www

标签: python django ubuntu uwsgi wsgi


【解决方案1】:

检查您对 Django 项目的文件权限。您已将 WSGI 工作人员配置为使用帐户“www-data”。将其更改为有权访问目录和文件的帐户,或更改文件权限。

您可以通过在目录中运行ls -la 来验证文件权限。第三列显示所有者,第四列显示组。

-rwxrwxrwx 1 lbird lbird      548 Nov  3 11:52  default-soapui-workspace.xml
-rwxrwxrwx 1 lbird lbird  2785280 Jun  5  2021  ntuser.dat.LOG1
-rwxrwxrwx 1 lbird lbird  3256320 Jun  5  2021  ntuser.dat.LOG2
-rwxrwxrwx 1 lbird lbird       20 Jun  5  2021  ntuser.ini
-rwxrwxrwx 1 lbird lbird     8677 Nov  3 11:52  soapui-settings.xml

您可以通过在项目目录中运行chown www-data:www-data ./* 来更改文件和文件夹权限。

我不建议将文件保存在您的根目录中,因为它应该受到保护。而是考虑将它们移至/var/www/var/app

要验证是否是权限问题,您可以更改 uWSGI 配置以使 uid 和 gid 成为 root,但不要在生产设置中使用它。

【讨论】:

    猜你喜欢
    • 2017-01-04
    • 1970-01-01
    • 2017-05-19
    • 2013-02-01
    • 2016-12-21
    • 1970-01-01
    • 1970-01-01
    • 2011-03-17
    • 1970-01-01
    相关资源
    最近更新 更多