2014-01-06 134 views
1

我有一個項目使用Django,我試圖在運行OS X Server(10.9)的機器上的本地網絡上部署Django。我可以使用項目的manage.py腳本在本地運行它,並擁有所有依賴關係和所有內容,但我一直在努力通過Server.app將它作爲常規網站運行。下面是配置文件在服務器上的Web應用程序所需要的項目,都指向實際代碼:在OS 10.9服務器上部署Django

/Library/Server/Web/Data/WebApps/project/.../ 

(它實際上沒有命名的項目,我保證):

/庫/服務器/Web/Config/apache2/httpd_project.conf

WSGIScriptAlias /unity /Library/Server/Web/Data/WebApps/unity/unity/site.wsgi 

/Library/Server/Web/Config/apache2/webapps/com.apple.webapp.project.plist

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN""http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict> 
<key>name</key> 
<string>com.apple.webapp.project</string> 
<key>displayName</key> 
<string>Daily Download</string> 
<key>launchKeys</key> 
<array/> 
<key>proxies</key> 
<dict/> 
<key>installationIndicatorFilePath</key> 
<string>/Library/Server/Web/Data/WebApps/project/project/site.wsgi</string> 
<key>includeFiles</key> 
<array> 
    <string>/Library/Server/Web/Config/apache2/httpd_project.conf</string> 
</array> 
<key>requiredModuleNames</key> 
<array> 
    <string>wsgi_module</string> 
</array> 

我已經將它作爲網站添加到了Server.app中。問題是,我得到500錯誤在/私營/無功以下條目/日誌/的Apache2/error_log中:

[Mon Jan 06 14:55:21 2014] [error] [client 17.19.244.170] ImportError: Could not import settings 'project.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named unity.settings 

這是怪我,因爲我已經添加該目錄到我的PYTHONPATH和能從Python提示符導入project.settings。至少它在調用我的代碼,但我無法弄清楚這個系統路徑問題。有任何想法嗎?

+0

我不知道任何關於Server.app,但什麼用戶它運行?你說這個目錄在你的PYTHONPATH中,但大概服務器沒有像你那樣運行。 –

+0

它以管理員帳戶運行,我手動添加(導出)PYTHONPATH到我的.bash_profile。現在我想到了,是否還有另一個地方需要指定它,以便它可以被Apache識別而不是bash會話? – drodman

回答

2

昨天我剛剛用OS 10.9服務器設置了django 1.6.1。

文件/Library/Server/Web/Config/apache2/httpd_wsgi2.conf [..]

WSGIScriptAlias//Users/jens/Source/macmini/macmini/macmini.wsgi 

<Directory /Users/jens/Source/macmini> 
Order allow,deny 
Allow from all 
</Directory> 

[..]

文件/庫/服務器/網絡/配置/的Apache2 /webapps/com.apple.webapp.wsgi2.plist

[...]

<?xml version="1.0" encoding="UTF-7"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict> 
     <key>name</key> 
     <string>com.apple.webapp.wsgi2</string> 
     <key>displayName</key> 
     <string>Django 1.6.1 Setup at/</string> 
     <key>launchKeys</key> 
     <array/> 
     <key>proxies</key> 
     <dict/> 
     <key>installationIndicatorFilePath</key> 
     <string>/Users/jens/Source/macmini/macmini/macmini.wsgi</string> 
     <key>includeFiles</key> 
     <array> 
       <string>/Library/Server/Web/Config/apache2/httpd_wsgi2.conf</string> 
     </array> 
     <key>requiredModuleNames</key> 
     <array> 
       <string>wsgi_module</string> 
     </array> 
</dict> 
</plist> 

[...]

Propably值得注意我延的家庭directoty內安裝的Django

[...]

macmini:macmini jens$ ls -l 
total 72 
-rw-r--r-- 1 jens staff  0 14 Jan 20:43 __init__.py 
-rw-r--r-- 1 jens staff 133 14 Jan 21:10 __init__.pyc 
-rwxr-xr-x 1 jens staff 482 15 Jan 09:43 macmini.wsgi 
-rw-r--r-- 1 jens staff 4384 15 Jan 17:15 settings.py 
-rw-r--r-- 1 jens staff 3902 15 Jan 17:16 settings.pyc 
-rw-r--r-- 1 jens staff 298 14 Jan 20:43 urls.py 
-rw-r--r-- 1 jens staff 413 14 Jan 21:53 urls.pyc 
-rwxr-xr-x 1 jens staff 466 14 Jan 23:46 wsgi.py 
-rw-r--r-- 1 jens staff 590 14 Jan 21:52 wsgi.pyc 

[...]

而且finaly的wsgi.py文件

[...]

""" 
WSGI config for macmini project. 

It exposes the WSGI callable as a module-level variable named ``application``. 

For more information on this file, see 
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/ 
""" 

import os 
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "macmini.settings") 

from django.core.wsgi import get_wsgi_application 
application = get_wsgi_application() 

[012]

確保您現在在Server.app內創建了一個虛擬站點。

乾杯,延斯

+0

非常感謝。 – mikec