Django mod_wsgi Apache 错误 403 在 Ubuntu 22.04 上禁止

Django mod_wsgi Apache 错误 403 在 Ubuntu 22.04 上禁止

Apache 应用程序上的 Django mod_wsgi 在 Ubuntu 20.04 及之前的版本中按照下面提到的配置运行良好,但是当我在 Ubuntu 22.04 中执行相同配置时,会出现 403 Forbidden 错误。并且在错误日志中出现 Permission denied: mod_wsgi。

我尝试更改所有文件的权限,但没有效果,

Apache 配置:

<VirtualHost *:80>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <Directory /home/ubuntu/mydjango/mydjango>
                <Files wsgi.py>
                        Require all granted
                </Files>
        </Directory>

        alias /static /home/ubuntu/mydjango/static
        <Directory /home/ubuntu/mydjango/static>
                Require all granted
        </Directory>

        WSGIDaemonProcess myapp python-home=/home/ubuntu/mydjango/venv python-path=/home/ubuntu/mydjango
        WSGIProcessGroup myapp
        WSGIScriptAlias / /home/ubuntu/mydjango/mydjango/wsgi.py
</VirtualHost>

Apache 错误日志:

Current thread 0x00007fb606719780 (most recent call first):
  <no Python frame>
[Sun Jun 05 05:59:07.594727 2022] [wsgi:warn] [pid 37044:tid 140419768883072] (13)Permission denied: mod_wsgi (pid=37044): Unable to stat Python home /home/ubuntu/mydjango/venv. Python interpreter may not be able to be initialized correctly. Verify the supplied path and access permissions for whole of the path.
Python path configuration:
  PYTHONHOME = '/home/ubuntu/mydjango/venv'
  PYTHONPATH = (not set)
  program name = 'python3'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = '/usr/bin/python3'
  sys.base_prefix = '/home/ubuntu/mydjango/venv'
  sys.base_exec_prefix = '/home/ubuntu/mydjango/venv'
  sys.platlibdir = 'lib'
  sys.executable = '/usr/bin/python3'
  sys.prefix = '/home/ubuntu/mydjango/venv'
  sys.exec_prefix = '/home/ubuntu/mydjango/venv'
  sys.path = [
    '/home/ubuntu/mydjango/venv/lib/python310.zip',
    '/home/ubuntu/mydjango/venv/lib/python3.10',
    '/home/ubuntu/mydjango/venv/lib/python3.10/lib-dynload',
  ]
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'

相关内容