python - 在 Django 中的 Linode Ubuntu 21.10 上运行的 Apache 2 出现 403 错误

标签 python django ubuntu apache2 wsgi

我正在关注 Coref Shafer 的“Python Django 教程:部署您的应用程序(选项 #1)-部署到 Linux 服务器”。
在我激活我的 Apache 2 服务器并尝试访问我的 Django 应用程序后,该页面返回 403 错误。检查我的错误日志后,我发现以下内容:

Current thread 0x00007f57a341f780 (most recent call first):
<no Python frame>
[Sat Nov 06 18:29:53.698451 2021] [wsgi:warn] [pid 24290:tid 140014377891712] (13)Permission denied: mod_wsgi (pid=24290): Unable to stat Python home /home/vavao/website/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/vavao/website/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/vavao/website/venv'
  sys.base_exec_prefix = '/home/vavao/website/venv'
  sys.platlibdir = 'lib'
  sys.executable = '/usr/bin/python3'
  sys.prefix = '/home/vavao/website/venv'
  sys.exec_prefix = '/home/vavao/website/venv'
  sys.path = [
    '/home/vavao/website/venv/lib/python39.zip',
    '/home/vavao/website/venv/lib/python3.9',
    '/home/vavao/website/venv/lib/python3.9/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'

Current thread 0x00007f57a341f780 (most recent call first):
<no Python frame>
这是我的 website.conf 文件
<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

    Alias /static /home/vavao/website/static
    <Directory /home/vavao/website/static>
        Require all granted
    </Directory>

    <Directory /home/vavao/website/website>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

    WSGIScriptAlias / /home/vavao/website/website/wsgi.py
    WSGIDaemonProcess django_app python-path=/home/vavao/website python-home=/home/vavao/website/venv
    WSGIProcessGroup django_app
</VirtualHost>
最令人困惑的是,当我设置 DEBUG = True 时,我没有从浏览器得到不同的响应。我收到相同的 403 错误。
我发现了以下 Github 问题:https://github.com/pyinstaller/pyinstaller/issues/5438
但是卸载软件包不是解决方案,我一开始没有安装这些软件包。
我该如何解决这个问题?

最佳答案

sudo chmod 711 /home/vavao解决了这个问题。

关于python - 在 Django 中的 Linode Ubuntu 21.10 上运行的 Apache 2 出现 403 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69866841/

相关文章:

django - 在Django的ORM中,有没有办法检测代码是否在事务内执行?

django - 删除 Django 应用程序后清理未使用的数据库表?

python - Django RadioSelect 从模型中选择

c++ - opencv ubuntu 12.04 Cmake错误: Source directory does not appear to contain CmakeLists. txt

python - 使用 Paramiko 在后台运行无限 Bash 循环

python - 使用动态正则表达式匹配字符串中的整个单词

python - 按索引删除列表元素是否比按值删除更有效?

python - Django Celery Eventlet - 获取 "No address found"错误

linux - SSH 连接到 ec2 连接超时

mongodb - 全新安装时出现 meteor 抛出错误 "Unexpected mongo exit code null. Restarting."