簡體   English   中英

django中帶有mod_wsgi的靜態文件

[英]static file with mod_wsgi in django

我搜索了很多,但我的django網站仍然存在靜態文件(css,image,...)的問題。

我在archlinux 64bits上使用帶有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和group devusers,包括我的用戶,http和root

在我的模板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文件有關(也許我錯了)但是肯定的是我應該能夠從apache文件夾外部使用django.wsgi

如果我用Alias /media /srv/http/media/更改Alias /media /home/mart/programmation/python/django/martfiles/media/ Alias /media /srv/http/media/並給出正確的權限,它就可以了。 但我不希望(也不應該)將我的所有媒體放在apache文件夾中

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

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

你的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可以真正訪問它們......

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

暫無
暫無

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

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