簡體   English   中英

Django和Apache2錯誤-您無權訪問此服務器上的/

[英]Django and Apache2 error - You don't have permission to access / on this server

我正在嘗試使用apache Web服務器將django應用程序部署到Digital Ocean。 我下面這個這個教程。 但是,當我嘗試遠程訪問我的網站時,出現錯誤:

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。 可能是什么問題呢?

這一點看起來不正確:

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

您的virtualenv在哪里? /opt~/opt 他們是兩個不同的地方。 在其他任何地方,您指的是/opt

我的與您的相似,並且運作良好。 我有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()

暫無
暫無

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

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