簡體   English   中英

Django mod_wsgi Apache 錯誤 403 禁止訪問 Ubuntu 22.04

[英]Django mod_wsgi Apache error 403 Forbidden on Ubuntu 22.04

Django Apache 上的 mod_wsgi 應用程序在 Ubuntu 20.04 和以前的版本中使用下面提到的配置工作正常,但是當我在 Ubuntu 22.04 中進行相同的配置時,它會出現 403 Forbidden error 權限被拒絕:錯誤日志中的 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'

默認情況下,Apache2 以無權(讀取/執行)主目錄權限的www-data用戶身份運行。 所以你也應該在主目錄上設置正確的權限:

sudo chmod 755 /home/ubuntu

或者您可以將項目放入默認情況下“其他人”可讀/可執行的/var/www中,這樣 Apache2 就可以從那里運行該項目。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM