【问题标题】:Deloying Django app Apach2: 403 Forbidden error. Permission denied: mod_wsgi部署 Django 应用程序 Apache2:403 禁止错误。权限被拒绝:mod_wsgi
【发布时间】:2021-12-07 22:57:52
【问题描述】:

我正在尝试使用我的 Digital Ocean 液滴部署我的 Django 应用程序。我遵循了一个非常有用的 YouTube 教程;当他在 Apache2 中调整设置,然后刷新时,他看到了他的 Django 应用程序,而当我这样做时,我收到以下错误:

Forbidden
You don't have permission to access this resource.
Apache/2.4.46 (Ubuntu) Server at 159.223.6.157 Port 80

在这里你可以看到我的 /etc/apache2/sites-available/hbm_project.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/hbm/hbm_project/static
    <Directory /home/hbm/hbm_project/static>
            Require all granted
    </Directory>

    <Directory /home/hbm/hbm_project/hbm_project>
            <Files wsgi.py>
                    Require all granted
            </Files>
    </Directory>

    WSGIScriptAlias / /home/hbm/hbm_project/hbm_project/wsgi.py
    WSGIDaemonProcess hbm_app python-home=/home/hbm/hbm_project/venv python-path=/home/hbm/hbm_project python-ho>
    WSGIProcessGroup hbm_app

当我查看 Apache2 的错误日志时,我看到以下错误:

    [Thu Oct 21 07:07:57.606866 2021] [wsgi:warn] [pid 35891:tid 139970948001088] (13)Permission denied: mod_wsgi (pid=35891): Unable to stat Python home /home/hbm/hbm_project/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/hbm/hbm_project/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/hbm/hbm_project/venv'
  sys.base_exec_prefix = '/home/hbm/hbm_project/venv'
  sys.platlibdir = 'lib'
  sys.executable = '/usr/bin/python3'
  sys.prefix = '/home/hbm/hbm_project/venv'
  sys.exec_prefix = '/home/hbm/hbm_project/venv'
  sys.path = [
    '/home/hbm/hbm_project/venv/lib/python39.zip',
    '/home/hbm/hbm_project/venv/lib/python3.9',
    '/home/hbm/hbm_project/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 0x00007f4d86a26d40 (most recent call first):
<no Python frame>

互联网上有一些类似的错误,但对其他人有用的东西似乎都不适合我。 希望有人能帮帮我。

谢谢!

【问题讨论】:

    标签: python django apache2 mod-wsgi http-status-code-403


    【解决方案1】:

    试试chown $USER:$USER /home/hbm/hbm_project

    【讨论】:

    • 嗨@balumn,感谢您的回复。我得到以下信息:hbm@hbm-server:~$ sudo chown -r hbm:hbm /home/hbm/hbm_project/ chown: invalid option -- 'r' 尝试 'chown --help' 了解更多信息。
    • @PatrickPel -r 已从答案中删除,也许现在试试?
    猜你喜欢
    • 2014-02-03
    • 2018-05-24
    • 2015-05-26
    • 2012-03-12
    • 2012-09-23
    • 1970-01-01
    • 2016-04-21
    • 2016-12-25
    • 2014-08-16
    相关资源
    最近更新 更多