【问题标题】:403 error with Apache 2 running on Linode Ubuntu 21.10 in Django在 Django 中的 Linode Ubuntu 21.10 上运行的 Apache 2 出现 403 错误
【发布时间】:2021-12-20 07:28:17
【问题描述】:

我正在关注 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

但是卸载软件包不是解决方案,我一开始没有安装这些软件包。

我该如何解决这个问题?

【问题讨论】:

    标签: python django ubuntu apache2 wsgi


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-19
      • 2015-12-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-29
      • 2011-04-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多