6

たくさん検索しましたが、django Webサイトの静的ファイル(css、image、...)にまだ問題があります。

archlinux64ビットでapacheを使用してmod_wsgiを使用しています

http.confに追加しました:

LoadModule wsgi_module modules/mod_wsgi.so

<VirtualHost *:80>
    WSGIDaemonProcess mart.localhost user=mart group=users processes=2 threads=25
    WSGIProcessGroup mart.localhost
    LogLevel debug

    Alias /media /home/mart/programmation/python/django/martfiles/media/
    <Directory /home/mart/programmation/python/django/martfiles/>
        Order allow,deny
        Allow from all
    </Directory>

    WSGIScriptAlias / /srv/http/wsgi-scripts/django.wsgi
</VirtualHost>

ホームフォルダでdjango.wsgiを使用しようとしましたが、機能しません( )(ここpermission denied to access /に示すテストスクリプトを使用すると、奇妙なことに機能します)

すべてのディレクトリとコンテンツ(apacheフォルダー、wsgi-script、martfiles)には775 root:devusers、ユーザー、http、rootを含むグループdevusersのアクセス許可があります。

テンプレートbase.htmlでは、cssを次のように呼び出します。

 <html>  <head>
     <link rel="stylesheet" href="/media/css/style.css" />

および/var/log/http/error.logのエラー

 [Sat Jan 16 13:22:21 2010] [error] [client 127.0.0.1] (13)Permission denied: access to /media/css/style.css denied, referer: http://localhost/
 [Sat Jan 16 13:22:21 2010] [info] mod_wsgi (pid=14783): Attach interpreter ''

/etc/httpd/conf/http.conf

/srv/http/wsgi-script/django.wsgi

/home/.../martfiles/settings.py

ありがとうございました


編集:私のdjango Webサイトが正常に機能していることを正確に示しています(セッションを除くが、関連しているとは思わない)ので、django.wsgiファイルに関連しているのかわかりません(おそらく私は間違っています)が、確かなことは何ですかapacheフォルダーの外からdjango.wsgiを使用できるはずです

Alias /media /home/mart/programmation/python/django/martfiles/media/で行を変更しAlias /media /srv/http/media/て適切な権限を与えると、機能します。しかし、私はすべてのメディアをapacheフォルダーに入れたくありません(そしてそうすべきではありません)。

4

3 に答える 3

7

静的ファイルを含むディレクトリ'/home / mart / programmation / python / django / martfiles / media'だけでは、読み取りと検索が可能であるだけでは不十分です。Apacheを実行するユーザーは、ルートディレクトリにバックアップするために、Apacheのすべての親ディレクトリへの読み取りおよび潜在的な検索アクセス権を持っている必要があります。多くのシステムのホームディレクトリは「rwx------」であるため、Apache構成のDeny / Allowディレクティブに関係なく、これはApacheアクセスを拒否します。

Djangoプロジェクトと静的ファイルをホームアカウントの外のどこかに配置し、必要に応じてファイルシステムのアクセス許可を緩和することをお勧めします。

于 2010-01-17T04:55:18.167 に答える
3

あなたのdjango.wsgiファイル、

WSGIScriptAlias / /srv/http/wsgi-scripts/django.wsgi

によって定義された範囲外です<Directory>

<Directory /home/mart/programmation/python/django/martfiles/>

これをに追加してみてくださいhttpd.conf

<Directory /srv/http/wsgi-scripts/>
    Order allow,deny
    Allow from all
</Directory>

django.wsgiまたは、ファイルをのどこかに置きます/home/mart/programmation/python/django/martfiles/。それはうまくいくはずです。

編集:了解しました。本番マシンで動作しているhttpd.confの例を次に示します。

<VirtualHost *:80>
    # Admin email, Server Name (domain name) and any aliases
    ServerAdmin testing@example.de
    ServerName  www.example.de

    DocumentRoot /home/example/testing/parts/public

    Alias /media /home/example/testing/parts/public/media

    # WSGI Settings
    WSGIDaemonProcess example user=example group=example threads=25
    WSGIProcessGroup example
    WSGIScriptAlias / /home/example/testing/parts/public/django.wsgi

    <Directory "/home/example/testing/parts/public">
        # Allow Apache to follow links
        Options FollowSymLinks
        # Turn on the ability to use .htaccess files
        AllowOverride All
        # Controls who can get stuff from this directory
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

したがって、dhango.wsgiが<Directory>ディレクティブによってアクセス可能として設定された場所で定義されているsudo su httpd場合、それがシステムでapacheを実行しているユーザーである場合は、cssファイルを読み取って、apacheが実際にそれらにアクセスできるかどうかを確認することもできます。 ..。。

于 2010-01-16T22:54:46.170 に答える
0

NameVirtualHostこれは、仮想サーバーをセットアップする場合に必要なディレクティブがhttp.confに表示されなかったことを除いて、私のアプリケーションにあるようです。NameVirtualHost *:80仮想ホスト定義の前に追加してみることができます。

于 2010-01-16T22:14:57.023 に答える