【问题标题】:Django Deployment with Apache/mod_wsgi on Mac OS X 10.9 with Server.app使用 Server.app 在 Mac OS X 10.9 上使用 Apache/mod_wsgi 部署 Django
【发布时间】:2015-04-17 15:43:06
【问题描述】:

过去两天我尝试在运行 Server.app 的 Mac 10.9 上部署一个带有夹层的 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 当然我在这里遗漏了一些东西......

这是我的设置: 带有服务器应用程序 3 的 Mac OS X 10.9 Python 2.7.9(通过 brew 安装) django 1.6.10 阿帕奇 2.2.26 mod_wsgi 4.4.8(通过 pip 表达的版本)

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

配置文件: 我将 wsgi.py 重命名为 MyProject.wsgi,它只是在 Server.app/Advanced 设置中列出了 MyProject,但仅此而已。值得一提的是:Apple 的默认“hello world python app”也不起作用,我没见过,但认为它与 Apple 提供的默认启动屏幕不同。

/Library/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 在开发服务器上运行良好 python manage.py runserver

mod_wsgi 似乎在 /private/etc/apache2/httpd.conf : LoadModule wsgi_module libexec/apache2/mod_wsgi.so 而且 mod_wsgi-express start-server 工作正常,至少对于 Malt Whyskey 飞溅。

但是当我进入 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

并且 echo $PYTHONPATH 说

/Users/_dev/MyProject/MyProject/:

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

干杯 约尔格

【问题讨论】:

    标签: python django macos apache mod-wsgi


    【解决方案1】:

    只是一个简短的说明...在朋友的大力帮助下,我设法完成了它。这是我的设置:

    /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()
    

    干杯, 约尔格

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-20
      • 2013-12-13
      • 2012-06-17
      • 2017-01-30
      • 2012-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多