2011-01-26 13 views
12

私はUbuntu 10.04を使用しています。
私はatest
という名前/home/wong2/Code/python/django2/下Djangoプロジェクトを作成し、ここで同じディレクトリに
をWSGIファイルsetting.wsgiを作成するには、setting.wsgiの内容です:Apache mod_wsgiエラー:禁止このサーバにアクセスする権限がありません

import os 
import sys 

path = '/home/wong2/Code/python/django2' 

if path not in sys.path: 
    sys.path.append(path) 
os.environ["DJANGO_SETTINGS_MODULE"] = "atest.settings" 
from django.core.handlers.wsgi import WSGIHandler 
application = WSGIHandler() 

、ここでは、私は私の私のhttpdに追加するものです。 CONF:

<VirtualHost *:80> 
    ServerName localhost 
    WSGIScriptAlias//home/wong2/Code/python/django2/setting.wsgi 
    <Directory /> 
     Options FollowSymLinks 
     AllowOverride None 
     Order deny,allow 
     Allow from all 
    </Directory> 
    <Directory "/home/wong2/Code/python/django2/atest"> 
     Order allow,deny 
     Allow from all 
    </Directory> 
</VirtualHost> 

私はhttp://localhostを訪問したときに問題があり、それは

を語ります

Forbidden

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

ありがとうございます。

+1

その最初のディレクトリのセクションを削除 - あなたはそれを必要としない、と私はそれがWSGIAliasをオーバーライドしていると思います。 –

答えて

13

2番目のディレクトリブロックは、WSGIスクリプトファイルがインストールされている場所と一致しません。 WSGIスクリプトファイルを、ソースコードや他の機密ファイルが存在する場所、つまり同じディレクトリまたはサブディレクトリに貼り付けることは、非常に悪いことです。その代わりにそれをそれ自身のサブディレクトリに張るべきです。したがって:

WSGIScriptAlias//home/wong2/Code/python/django2/atest/apache/setting.wsgi 
<Directory "/home/wong2/Code/python/django2/atest/apache"> 
    Order allow,deny 
    Allow from all 
</Directory> 

したがって、 'atest'の下に 'apache'サブディレクトリを作成します。 'apache'サブディレクトリに 'setting.wsgi'を移動し、上記のようにconfigを変更してください。

あなたの問題は、Apacheが内部を見ることができないため、ホームディレクトリの制限的なパーミッションによっても発生する可能性があります。

Goが見る:

http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6#Conference_Presentations

それはこれらのアクセス許可の問題だけでなく、あなたのコードとWSGIスクリプトファイルを固執する場所のような問題点を説明しているように。

も読み:

http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

0

try http://localhost/index.htmlこれはApacheページを表示しますか?

wsgiがrootで正しく設定されていれば、正しく動作しません。

あなたがWWWフォルダのディレクトリ一覧

編集のためのウェブサーバを尋ねるかもしれないので、あなたは、そのエラーメッセージが表示されます。

私のプロジェクトは

の/ var/pyproj //に常にありますpysrc/ とサーバファイルを入れました /var/py_proj // server/

ここに私のwsgiスクリプトに行きます

import os, sys 

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 
import site 

PROJECT_ROOT = abspath(join(dirname(__file__), "../pysrc")) 
SETTINGS_LOC = abspath(join(PROJECT_ROOT, '')) 
site.addsitedir(SETTINGS_LOC) 
os.environ["DJANGO_SETTINGS_MODULE"] = "settings" 

from django.core.management import setup_environ 
import settings 
setup_environ(settings) 

sys.path.insert(0, join(PROJECT_ROOT, "apps")) 

from django.core.handlers.wsgi import WSGIHandler 

application = WSGIHandler() 

と私はvhost.conf私はこの

<VirtualHost *:8080> 
     DocumentRoot /var/www/ 

     <Directory /var/www/> 
       Order deny,allow 
       Allow from all 
       Options -Indexes FollowSymLinks 
       DirectoryIndex index.php 
       AllowOverride None 
     </Directory> 

     ServerAdmin [email protected] 

     LogLevel error 
     ErrorLog /var/srv_logs/apache_error.log 
     CustomLog /var/srv_logs/apache_access.log combined 
     #insert 
     Include /var/py_proj/pinax_demo/server/vhost.conf 
     Include /var/py_proj/<other>/server/vhost.conf 
     Include /var/py_proj/<other>/server/vhost.conf 

</VirtualHost> 

のhttpd.confが空であるように見えるファイル内のサイトで入手可能なフォルダに含ま

WSGIDaemonProcess pinax_demo user=www-data group=www-data threads=10 python-path=/var/.virtualenvs/pinax_demo/lib/python2.6/site-packages 

<Directory /var/py_proj/pinax_demo/server/> 
    Order deny,allow 
    Allow from all 
</Directory> 

Alias /pinax_demo /var/py_proj/pinax_demo/server/pinax_demo.wsgi 
<Location /pinax_demo/> 
    #WSGIProcessGroup must match the WSGIDaemonProcess 
    WSGIProcessGroup pinax_demo 
    SetHandler wsgi-script 
    Options +ExecCGI 
</Location> 

を使用しています。 Apacheは静的なファイルを送信する際にもひどいので、Apacheの設定はポート8080に、nginxの設定はポート80でapacheに転送します。私のサイトのポートを変更するだけで、nginxを使わずに実行することができるはずですが、私はそのようには行けません。

+0

私はhttp://localhost/index.htmlにアクセスしても、 '403 Forbidden'エラー – wong2

+0

を表示しています。もう一度考えると、あなたの問題は単にアクセス権の問題かもしれません。もしwww-data(linux apache user)があなたのホームディレクトリを読んでそのエラーを投げるかもしれないなら。 – Plahcinski

5

を私が原因制限されたファイルのパーミッションに同じ問題を抱えていました。その誰も他の意味

ls -l /home/ 

drwx------ 36 user user 12288 Nov 28 20:56 user

が、自分でもそのフォルダを閲覧することができます:

は、デフォルトでは、ホームフォルダのユーザーが設定されています。フォルダにオプションを実行する追加

は、あなたがあなたのWSGIがホームディレクトリを持っている驚きを得ることができます

chmod o+x /home/user/ 
ls -l /home/ 

drwx-----x 36 user user 12288 Nov 28 20:56 user

-1

私の問題を修正しました!私確かにナイーブwsgi_modのインストールでは、それは/ある - 私は私が作るために、このスクリプトを書かなければならなかったので、驚いたことを確認:

:フルパスが必要になりますインポートしたアプリケーションを意味

import os 

def application(environ, start_response): 
    status = '200 OK'; e=os.listdir(os.getcwd()) 
    output = '''WSGI %s<hr>'''%(e) 
    response_headers = [('Content-type', 'text/html'), 
         ('Content-Length', str(len(output)))] 
    start_response(status, response_headers) 
    return [output] 

は、例えば発見されます

この

sys.path.append('/home/foo/www/Forms') 
from DataCommon import page 
はこれにアプローチ(Googleが)をお勧めします。

ジャンゴで
import sys; path='/home/foo/www/Forms'; 
if path not in sys.path: sys.path.append(path) 
8

は1.5+あなたがマニュアルに記載提案方法を使用する必要があります。

WSGIScriptAlias//path/to/mysite.com/mysite/wsgi.py 
WSGIPythonPath /path/to/mysite.com 

<Directory /path/to/mysite.com/mysite> 
<Files wsgi.py> 
Require all granted 
</Files> 
</Directory> 

https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/modwsgi/

+0

''を追加しました。 – Renato

+0

同じです。さらにを追加しました。どうもありがとう。 – Yathi

+0

FYI - 'Require all'はApache 2.4.xでのみ動作し、OPの 'httpd.conf'に基づいて、彼は2.2.xを使用しています。それは良い答えだ! – Drewness

関連する問題