2010-01-16 86 views
6

我搜索了很多,但我仍然有與我的django網站的靜態文件(CSS,圖像,...)的問題。靜態文件與Django中的mod_wsgi

我使用的mod_wsgi和Apache上的archlinux 64位

我在我的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 /)(奇怪的是它的工作原理,如果我用給here測試腳本)

所有的目錄和內容(阿帕奇文件夾,WSGI腳本,martfiles)與本集團devuse許可775 root:devusers RS包括我的用戶,HTTP和根

在我的模板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的網站工作正常(會議除外,但我不認爲這是相關的),所以我不知道它是關係到django.wsgi文件(也許我錯了),但肯定的是,我應該可以,如果我改線Alias /media /home/mart/programmation/python/django/martfiles/media/使用django.wsgi從Apache文件夾

外側Alias /media /srv/http/media/並給出正確的權限,有用。但我不希望(也不應該)把我的所有媒體放在apache文件夾中

回答

7

僅包含目錄'/ home/mart/programmation/python/django/martfiles/media'是不夠的靜態文件是可讀和可搜索的。 Apache運行的用戶必須具有讀取和潛在的搜索訪問權限,將其所有父目錄備份到根目錄。由於許多系統上的主目錄是'rwx ------',因此不管Apache配置中的Deny/Allow指令如何,這都會拒絕Apache訪問。

建議您將Django項目和靜態文件放置在您家庭帳戶的某處,並根據需要放寬文件系統權限。

+0

這就是爲什麼我給了775權限包含我的apache用戶(HTTP)的組devusers。哪裏和哪個許可?我來試試 – 2010-01-17 06:32:29

+0

我把我的媒體在/ usr /共享/ Django的只有root權限和它的作品!非常感謝 – 2010-01-17 10:53:54

+2

+1修復我的錯誤。將家庭權限設置爲755的安全含義是什麼? – g33kz0r 2010-03-27 20:21:06

0

這似乎是我的應用程序,除了我沒有在http.conf中看到NameVirtualHost指令如果你想設置虛擬服務器,這是必需的。您可以嘗試在虛擬主機定義之前添加NameVirtualHost *:80

+0

如果我這樣做,我已經有了一個更多的錯誤在error.log中:「[錯誤]虛擬主機*:80 - 混合*用了NameVirtualHost地址端口和非*端口不支持,有不確定的結果出發' – 2010-01-17 06:35:32

+0

對不起,它應該是'NameVirtualHost *:80'。更新了答案。 – abhaga 2010-01-17 08:16:10

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文件的某處在之內。這應該工作。

編輯:好的,這裏是一個例子httpd。CONF正在工作的生產機器上:

<VirtualHost *:80> 
    # Admin email, Server Name (domain name) and any aliases 
    ServerAdmin [email protected] 
    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文件,看看阿帕奇是否可以真正訪問它們...

+0

如果我把django.wsgi放在martfiles中,我有一個錯誤403訪問被拒絕([error] [client 127.0.0.1](13)Permission denied:access to/denied)。如果我添加<目錄/ SRV ...它不會改變任何東西([錯誤] [客戶端127.0.0.1](13)權限被拒絕:訪問/media/css/style.css否認,引用者:HTTP:/ /本地主機/)。 – 2010-01-17 06:30:07

+0

嘗試在''部分中簡單地添加'DocumentRoot/home/mart/programmation/python/django/martfiles'。 – 2010-01-17 10:48:18

+0

把.htaccess文件放在哪裏? – sharafjaffri 2013-11-05 14:11:15