2013-02-16 84 views
-1

我一直在Django本地工作,現在我試圖將一些代碼推送到我運行的Ubuntu服務器上的生產Apache環境(http://www.youtube.com/watch?v=hBMVVruB9Vs)。Django + Apache - wsgi trouble

但是,我只是得到目錄中的文件列表,沒有別的。首先,我通過在終端運行Python命令來確保安裝了Python。

我已經安裝apaache和MOD WSGI用下面的命令:

sudo易於得到安裝的Apache2 命令和apt-get安裝中的libapache2-MOD-WSGI

而且我測試過地看到,其啓用。

這裏是我的wsgi文件firstweb.wsgi它位於根:

import os 
import sys 
sys.path.append('/var/www/firstweb') 
os.environ['DJANGO_SETTINGS_MODULE'] = 'firstweb.settings' 

import django.core.handlers.wsgi 
application = django.core.handlers.wsgi.WSGIHandler() 

這裏是我的firstweb.conf文件:

<VirtualHost *:80> 

WSGIScriptAlias//firstweb.wsgi 

Alias /static /var/www/firstweb/static 

<Directory /var/www/firstweb/> 
Order allow,deny 
Allow from all 
</Directory> 

</VirtualHost> 

和我的Django項目位於:/ VAR/www/firstweb/

我真的不能解決這裏有什麼問題,在視頻裏它運行的很好! :(

編輯,這裏是錯誤日誌:

[Sat Feb 16 16:19:31 2013] [notice] Apache/2.2.22 (Ubuntu) configured -- resuming normal operations 
[Sat Feb 16 16:20:46 2013] [notice] caught SIGTERM, shutting down 
[Sat Feb 16 16:20:47 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+. 
[Sat Feb 16 16:20:47 2013] [warn] mod_wsgi: Runtime using Python/2.7.3. 
[Sat Feb 16 16:20:47 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations 
[Sat Feb 16 16:37:05 2013] [notice] caught SIGTERM, shutting down 
[Sat Feb 16 16:37:06 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+. 
[Sat Feb 16 16:37:06 2013] [warn] mod_wsgi: Runtime using Python/2.7.3. 
[Sat Feb 16 16:37:06 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations 
[Sat Feb 16 16:37:17 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico 
[Sat Feb 16 16:37:20 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico 
[Sat Feb 16 16:37:24 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico 
[Sat Feb 16 16:37:24 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico 
[Sat Feb 16 16:37:24 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico 
[Sat Feb 16 16:37:25 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico 
[Sat Feb 16 16:37:25 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico 
[Sat Feb 16 16:37:26 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico 
[Sat Feb 16 16:38:01 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico 
[Sat Feb 16 16:39:19 2013] [notice] caught SIGTERM, shutting down 
[Sat Feb 16 16:39:20 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+. 
[Sat Feb 16 16:39:20 2013] [warn] mod_wsgi: Runtime using Python/2.7.3. 
[Sat Feb 16 16:39:20 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations 
[Sat Feb 16 16:39:24 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico 
[Sat Feb 16 16:39:42 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico 
[Sat Feb 16 16:48:00 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico 
[Sat Feb 16 16:48:02 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico 
[Sat Feb 16 16:49:51 2013] [notice] caught SIGTERM, shutting down 
[Sat Feb 16 16:49:52 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+. 
[Sat Feb 16 16:49:52 2013] [warn] mod_wsgi: Runtime using Python/2.7.3. 
[Sat Feb 16 16:49:52 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations 
[Sat Feb 16 16:49:55 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico 
[Sat Feb 16 16:49:56 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico 
[Sat Feb 16 16:49:58 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico 
[Sat Feb 16 16:53:21 2013] [notice] caught SIGTERM, shutting down 
[Sat Feb 16 16:53:22 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+. 
[Sat Feb 16 16:53:22 2013] [warn] mod_wsgi: Runtime using Python/2.7.3. 
[Sat Feb 16 16:53:22 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations 
[Sat Feb 16 16:55:34 2013] [notice] caught SIGTERM, shutting down 
[Sat Feb 16 16:55:35 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+. 
[Sat Feb 16 16:55:35 2013] [warn] mod_wsgi: Runtime using Python/2.7.3. 
[Sat Feb 16 16:55:35 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations 
[Sat Feb 16 17:00:07 2013] [notice] caught SIGTERM, shutting down 
[Sat Feb 16 17:00:08 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+. 
[Sat Feb 16 17:00:08 2013] [warn] mod_wsgi: Runtime using Python/2.7.3. 
[Sat Feb 16 17:00:08 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations 
+0

你可以看看你的apache日誌 - 應該在/ var/logs/httpd或/ var/logs/apache – 2013-02-16 17:55:50

+0

我已經看過:/ var/log/apache2 /並且有三個文件,檢出了錯誤日誌,除了python版本不匹配之外,我沒有看到任何明顯的東西: – user2078888 2013-02-16 18:25:53

+0

反正告訴我們 - 當你測試時你會得到什麼屏幕 - 它看起來像什麼?什麼是不工作關於它 – 2013-02-16 18:39:14

回答

0

嘗試配置您的虛擬主機像這樣:

<Directory /var/www/firstweb/static> 
    Order allow,deny 
    Option Indexes 
    Allow from all 
    </Directory> 

    WSGIScriptAlias//full-system-path-to/firstweb/wsgi.py 

如果不工作 - 只是進行了更改目錄和標籤添加靜態到結束,就像我上面 - 我想通過不添加靜態,它顯示目錄中的文件

+0

不,這給了我一個關於Option Index的錯誤,所以我將它刪除了。我也把我的整個項目從web目錄移動到了我的主目錄(/ home/ubuntu/firstweb),我試圖以各種方式重寫所有內容而沒有任何結果。我也從www文件夾中刪除了firstweb目錄。除了常規索引頁面之外,我沒有從wsgi/apache獲取任何內容。 – user2078888 2013-02-16 19:51:58

0

配置您的虛擬主機,如:

<VirtualHost *:80> 
ServerName mysite.com 
ServerAlias www.mysite.com 
DocumentRoot /var/production/myApp 

<Directory /> 
    Order Deny,Allow 
    Deny from all 
    Options None 
    AllowOverride None 
</Directory> 
<Directory /var/production/myApp> 
    Options None 
    AllowOverride None 
    Order allow,deny 
    allow from all 
</Directory> 

WSGIDaemonProcess mysite.com python-path=/var/production/myApp:/var/production/myApp/venv/lib/python2.7/site-packages 
WSGIProcessGroup misite.com 
WSGIScriptAlias//var/production/myApp/myApp/wsgi.py 

Alias /static /var/production/myApp/static 

<Directory /var/production/myApp/static> 
    Options None 
    AllowOverride None 
    Order Allow,Deny 
    Allow from all 
</Directory> 

替代對象 「的/ var /生產/對myApp」 到你的應用程序路徑

如果您需要更多的幫助,看看這個tutorial

0

問題1:你有沒有啓用WSGI國防部?

sudo a2enmod mod-wsgi 

問題2:你的AddHandler語句在哪裏?

<Directory /var/www/> 
    Options Indexes FollowSymLinks MultiViews ExecCGI 
    AddHandler cgi-script .cgi 
    AddHandler wsgi-script .wsgi 
    AllowOverride None 
    Order allow,deny 
    allow from all 
</Directory> 

我不認爲Apache知道如何.wsgi文件關聯到WSGI應用。

+0

如果你想看看他們做了什麼,這是我從中獲得信息的地方。 http://ubuntuforums.org/showthread.php?t=833766 – NuclearPeon 2014-05-23 21:54:11