【问题标题】:Django and Apache2 error - You don't have permission to access / on this serverDjango 和 Apache2 错误 - 您无权访问此服务器上的 /
【发布时间】:2014-11-24 11:35:46
【问题描述】:

我正在尝试使用 apache Web 服务器将我的 django 应用程序部署到 Digital Ocean。我正在关注thisthis 教程。但是,当我尝试远程访问我的网站时,我收到了错误:

Forbidden
You don't have permission to access / on this server.

我的网站虚拟主机文件,即 teenvestor,如下所示:

<VirtualHost *:80>
        ServerName teenvestor.co.uk
        ServerAlias www.teenvestor.co.uk
        WSGIScriptAlias / /opt/teenvestor/teenvestor/apache/django.wsgi

        Alias /static/ /opt/teenvestor/teenvestor/static/
        <Location "/static/">
            Options -Indexes
        </Location >
</VirtualHost>

我已启用该网站。 我的 django.wsgi 文件如下所示:

import os
import sys
import site

# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/opt/teenvestor/lib/python2.7/site-packages')

# Add the app's directory to the PYTHONPATH
sys.path.append('/opt/teenvestor/teenvestor')
sys.path.append('/opt/teenvestor/teenvestor/teenvestor')

os.environ['DJANGO_SETTINGS_MODULE'] = 'teenvestor.settings'

# Activate your virtual env
activate_env=os.path.expanduser("~/opt/teenvestor/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

PS:我正在使用 virtualenv。可能是什么问题?

【问题讨论】:

    标签: python django apache linux-mint


    【解决方案1】:

    这点看起来不对:

    activate_env=os.path.expanduser("~/opt/teenvestor/bin/activate_this.py")
    

    你的虚拟环境在哪里?在/opt~/opt?他们是两个不同的地方。在其他任何地方,您指的是/opt

    【讨论】:

      【解决方案2】:

      我的和你的差不多,工作正常。我有 django 和 django.setup() 的导入

      import os
      import sys
      import site
      import django
      import logging
      
      
      logger = logging.getLogger("")
      logger.setLevel(logging.DEBUG)
      handler = logging.StreamHandler(sys.stderr)
      handler.setLevel(logging.DEBUG)
      formatter = logging.Formatter('%(levelname)-8s %(messages)s')
      handler.setFormatter(formatter)
      logger.addHandler(handler)
      
      sys.stdout = sys.stderr
      from os.path import abspath, dirname, join
      
      
      # Add the site-packages of the chosen virtualenv to work with
      site.addsitedir('/home/xxxxxxx/workspace/djangoEnv/lib/python3.4/site-packages')
      
      # Add the app's directory to the PYTHONPATH
      sys.path.append('/home/xxxxxxx/workspace/djangoEnv/xxxxxxx')
      sys.path.append('/home/xxxxxxx/workspace/djangoEnv/xxxxxxx/xxxxxxx')
      
      os.environ['DJANGO_SETTINGS_MODULE'] = 'xxxxxxx.settings'
      
      
      
      # Activate your virtual env
      activate_env=os.path.expanduser("/home/xxxxxxx/workspace/djangoEnv/bin/activate_this.py")
      execfile(activate_env, dict(__file__=activate_env))
      
      django.setup()
      
      import django.core.handlers.wsgi
      application = django.core.handlers.wsgi.WSGIHandler()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-09
        • 1970-01-01
        • 2020-10-28
        • 2017-02-26
        • 2013-06-30
        • 2019-02-22
        相关资源
        最近更新 更多