使用Server.app在Mac OS X 10.9上使用Apache / mod_wsgi进行Django部署

时间:2015-02-17 01:15:39

标签: python django macos apache mod-wsgi

我花了两天时间尝试在运行Server.app的Mac 10.9上使用mezzanine部署Django项目。我学到了很多,但到目前为止没有运气。我已经阅读了几个关于这个主题的帖子:

https://apple.stackexchange.com/questions/151388/can-i-deploy-my-django-site-to-os-x-server Deploying Django on OS 10.9 Server

但是这些方法对我没用。

我一遍又一遍地浏览了djangoproject上的文档,但我找不到解决方案。所以请耐心等待,我相信有一个解决方案。

我想尽可能简单地做到这一点,甚至为了Apple的Server.app而省略了virtualenv 我肯定在这里遗漏了一些东西......

这是我的设置: 带有Server App 3的Mac OS X 10.9 Python 2.7.9(通过brew安装) django 1.6.10 Apache 2.2.26 mod_wsgi 4.4.8(通过pip表达版本)

项目代码本身位于/ Users / _dev / MyProject / MyProject

conf文件: 我将wsgi.py重命名为MyProject.wsgi,它刚刚在Server.app/Advanced设置中列出了MyProject,但仅此而已。值得一提的是:苹果defaut“hello world python app”也不起作用,我从来没有看过它,但认为它与苹果公司提供的狡猾的闪屏不同。

Server / Web / Config / apache2 /

中的httpd_wsgi2.conf
WSGIScriptAlias / /Users/_dev/MyProject/MyProject/MyProject.wsgi

<Directory /Users/_dev/MyProject/MyProject>
<Files MyProject.wsgi>
Order deny,allow
Allow from all
</Files>
</Directory>

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

/Users/_dev/MyProject/MyProject/MyProject.wsgi<?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>Hot Club Setup at /</string>
        <key>launchKeys</key>
        <array/>
        <key>proxies</key>
        <dict/>
        <key>installationIndicatorFilePath</key>
        <string>/Users/_dev/MyProject/MyProject/MyProject.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>

至少Django和Mezzanine与Development Server运行良好 python manage.py runserver

mod_wsgi似乎被激活了 /private/etc/apache2/httpd.conf:FilterModule wsgi_module libexec / apache2 / mod_wsgi.so 并且mod_wsgi-express start-server工作正常,至少对于Malt whyskey splash来说。

但是当我输入mod_wsgi-express start-server MyProject.wsgi时 我得到一个内部服务器错误 日志在/ tmp / mod_wsgi-localhost:8000:507 / error_log说:

ImportError: Could not import settings 'MyProject.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named MyProject.settings

比添加

PYTHONPATH="/Users/_dev/MyProject/MyProject/:$PYTHONPATH"
export PYTHONPATH

到/User/_dev/.bash_profile

回声$ PYTHONPATH说

/Users/_dev/MyProject/MyProject/:

我做错了什么?非常欢迎任何帮助。

欢呼声 约尔格

1 个答案:

答案 0 :(得分:2)

快速说明......在朋友的帮助下,我设法完成了它。这是我的设置:

/Library/Server/Web/Config/apache2/httpd_wsgi2.conf

Alias /robots.txt /Users/_dev/hotclub/hotclub/static/robots.txt
Alias /favicon.ico /Users/_dev/hotclub/hotclub/static/img/favicon.ico

Alias /media/ /Users/_dev/hotclub/hotclub/static/media/
Alias /static/ /Users/_dev/hotclub/hotclub/static/

<Directory /Users/_dev/hotclub/hotclub/static>
Order allow,deny
Allow from all
</Directory>

<Directory /Users/_dev/hotclub/hotclub/static/media>
Order allow,deny
Allow from all
</Directory>

WSGIScriptAlias / /Users/_dev/hotclub/hotclub/hotclub.wsgi

<Directory /Users/_dev/hotclub/hotclub>
Order allow,deny
Allow from all
</Directory>

/Library/Server/Web/Config/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>Hot Club Setup at /</string>
        <key>launchKeys</key>
        <array/>
        <key>proxies</key>
        <dict/>
        <key>installationIndicatorFilePath</key>
        <string>/Users/_dev/hotclub/hotclub/hotclub.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>

/Users/_dev/MyProject/MyProject/MyProject.wsgi

来自将来导入unicode_literals

import os
import sys

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
#PROJECT_ROOT = "/Users/_dev/hotclub/hotclub"
settings_module = "%s.settings" % PROJECT_ROOT.split(os.sep)[-1]
os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings_module)

sys.path.append('/Users/_dev/hotclub')
sys.path.append('/Users/_dev/hotclub/hotclub')

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

欢呼声, 约尔格