我发现许多类似的文章都有类似的问题,其中一些文章的结论是 Apache 服务根本无法在我的情况下运行。不过,我确实让该服务运行起来——只是它需要在安全方面进行不需要的设置。
情况是:我有一个使用 mod_wsgi 5.0.0 在 Apache 2.4 中托管的 Django 4.2.9 项目,全部位于 Windows 2016 Server 上。
当我从服务器帐户的命令行运行 Apache 时Administrator
,它工作得很好。
当我使用安装 Apache 2.4 服务httpd.exe -k install
,然后手动重新配置该服务以登录时.\Administrator
,它也可以正常工作。
LocalSystem
但是,如果我以或任何其他用户帐户登录 运行服务,该服务将无法启动。(旁注:我已确认所有帐户都启用了“作为服务登录”权限,因此这不是问题。) 错误如下所示:
而且httpd.exe
,如果我尝试从不同用户帐户的命令行运行,可执行文件将失败。日志文件中生成的错误是:
[Fri Jan 05 14:28:08.201284 2024] [wsgi:info] [pid 5712:tid 372] mod_wsgi (pid=5712): Initializing Python.
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = 'python'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = 'D:\\Program Files\\Apache24\\bin\\httpd.exe'
sys.base_prefix = 'C:\\Program Files\\Python310'
sys.base_exec_prefix = 'C:\\Program Files\\Python310'
sys.platlibdir = 'lib'
sys.executable = 'D:\\Program Files\\Apache24\\bin\\httpd.exe'
sys.prefix = 'C:\\Program Files\\Python310'
sys.exec_prefix = 'C:\\Program Files\\Python310'
sys.path = [
'C:\\Program Files\\Python310\\python310.zip',
'.\\DLLs',
'.\\lib',
'D:\\Program Files\\Apache24\\bin',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x000011d8 (most recent call first): <no Python frame>
[Fri Jan 05 14:28:08.217284 2024] [mpm_winnt:crit] [pid 4432:tid 368] AH00419: master_main: create child process failed. Exiting.
因此,这里的共同因素似乎是它适用于该Administrator
帐户,但不适用于任何其他帐户。我只是不明白为什么......或者如何纠正它。
更多相关信息:这是我从命令中获取的 wsgi 配置信息mod_wsgi-express module-config
,并将其粘贴到我的httpd.conf
文件中:
LoadFile "C:/Program Files/Python310/python310.dll"
LoadModule wsgi_module "D:/CSCatalog/django-projects/code/cscr/.venv/lib/site-packages/mod_wsgi/server/mod_wsgi.cp310-win_amd64.pyd"
WSGIPythonHome "D:/CSCatalog/django-projects/code/cscr/.venv"
是错误消息。
encodings
是一个系统模块,因此它应该在默认安装路径中可用。我的猜测是管理员用户
PYTHONPATH
设置了环境变量,但其他用户没有设置,因此出现错误消息。您可以设置服务的环境变量。
尝试将服务配置为以您要使用的特定用户启动,但之前您需要向该用户授予“作为服务登录”权限