如何在OS X Server上部署django应用程序? [英] How does one deploy a django application on OS X Server?

查看:141
本文介绍了如何在OS X Server上部署django应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在OS X Server 2.0上部署Django应用程序,而不使用自制软件或与OS X 10.8.1附带的Python不同的python风格?我在Django应用程序中使用可可绑定,并且无法使其在桌面计算机上运行homebrew(运行OS X 10.8.1);因此请求在系统安装的Python版本上部署应用程序。



我有以下OS X Server环境,其中已经安装了以下内容:




  • OS X 10.8.1

  • OS X Server 2.0

  • Python 2.7 .2

  • Apache 2.2.22



使用以下命令安装Django 1.4.1 :

  sudo easy_install django 

我的第一个尝试是部署一个空的网站,一旦成功,部署一个真正的应用程序,用于生产。该项目使用以下命令



<$ p创建在 / Library / Server / Web / Data / WebApps / mysite / $ p> django-admin.py startproject mysite

我运行应用程序使用以下命令。它只是确认应用程序已启动并运行。它是标准它的工作!第一次创建一个项目的页面。

  python manage.py runserver 8080 
/ pre>

然后,我创建了一个文件 /Library/Server/Web/Config/apache2/httpd_mysite.conf 以下内容:

  WSGIScriptAlias / mysite /Library/Server/Web/Data/WebApps/mysite/mysite/wsgi.py 

我进一步创建了一个文件 / Library / Server / Web / Config / apache2 / webapps / com.example.mysite.wsgi.plist 包含以下内容:

 <? xml version =1.0encoding =UTF-7?> 
<!DOCTYPE plist PUBLIC - // Apple // DTD PLIST 1.0 // ENhttp://www.apple.com/DTDs/PropertyList-1.0.dtd\">
< plist version =1.0>
< dict>
< key> name< / key>
< string> com.example.mysite.wsgi< / string>
< key> displayName< / key>
< string> Python我的网站应用< / string>
< key> launchKeys< / key>
< array />
< key>代理< / key>
< dict />
< key> installationIndicatorFilePath< / key>
< string> /Library/Server/Web/Data/WebApps/mysite/mysite/wsgi.py< / string>
< key> includeFiles< / key>
< array>
< string> /Library/Server/Web/Config/apache2/httpd_mysite.conf< / string>
< / array>
< key> requiredModuleNames< / key>
< array>
< string> wsgi_module< / string>
< / array>
< / dict>
< / plist>

文件 com.example.mysite.wsgi.plist 改编自 com.apple.webapp.wsgi.plist httpd_mysite.conf 改编自 httpd_wsgi.conf 。这两个文件都用于在通过服务器管理器配置时成功运行独立python应用程序。



然后,我创建了一个服务器管理器的站点,确认我的应用程序是在Web应用程序列表中。但是,当我访问 http://example.com/mysite 时,我收到一个500错误。日志有以下条目(出于隐私原因,IP地址更改为1.2.3.4):

  [Sat Sep 01 21:49 :17 2012] [warn] Init:基于名称的SSL虚拟主机仅适用于具有TLS服务器名称指示支持的客户端(RFC 4366)
[Sat Sep 01 21:49:17 2012] [notice] Apache / 2.2 .32(Unix)PHP / 5.3.13与Suhosin-Patch mod_wsgi / 3.3 Python / 2.7.2 mod_fastcgi / 2.4.6 mod_ssl / 2.2.22 OpenSSL / 0.9.8r配置DAV / 2恢复正常操作
[Sat Sep 01 21:50:13 2012] [error] [client 1.2.3.4](8)Exec格式错误:/Library/Server/Web/Data/WebApps/mysite/mysite/wsgi.py的exec失败
[Sat Sep 01 21:50:13 2012] [error] [client 1.2.3.4]脚本头的过早结束:wsgi.py

WSGI模块似乎不处理请求,而是可以使用FCGI处理请求。但是,日志表示已加载 mod_wsgi / 3.3



当我创建了一个标准的Python应用程序,如下所示:

  status ='200 OK'
output ='Hello World!'

response_headers = [('Content-type','text / plain'),
('Content-Length',str(len(output))]]
start_response(status,response_headers)

return [output]

并更新文件以指向 / Library / Server / Web / Data / WebApps / helloworld.wsgi 而不是 /Library/Server/Web/Data/WebApps/mysite/mysite/wsgi.py 然后显示Hello World 。因此,我假设wsgi被正确配置并能够执行应用程序,而且我的设置有其他问题。

解决方案

配置与发行版映射.py到CGI或FASTCGI,这将与mod_wsgi冲突。这就是为什么mod_wsgi建议使用.wsgi扩展名。所以,将'wsgi.py'重命名为'site.wsgi',然后在WSGIScriptAlias中使用'site.wsgi'。



BTW,你能确认有一个预编译的mod_wsgi.so随山狮服务器一起提供。


How would one deploy a Django application on OS X Server 2.0 without using homebrew or a different flavor of python than the one shipped with OS X 10.8.1? I'm using the cocoa bindings in a Django application and had trouble getting it to work with homebrew on my desktop machine (running OS X 10.8.1); hence the request to deploy the application on the system installed version of Python.

I have the following OS X Server environment, with the following already installed:

  • OS X 10.8.1
  • OS X Server 2.0
  • Python 2.7.2
  • Apache 2.2.22

Django 1.4.1 was installed using the following command:

sudo easy_install django

My first attempt is to deploy an empty website, and once that succeeds, deploy a real application to be used in production. The project was created at /Library/Server/Web/Data/WebApps/mysite/ using the following command

django-admin.py startproject mysite

I ran the application using the following command. It simply confirmed that the application was up and running. It is the standard "It worked!" page when you first created a project.

python manage.py runserver 8080

I then created a file /Library/Server/Web/Config/apache2/httpd_mysite.conf with the following content:

WSGIScriptAlias /mysite /Library/Server/Web/Data/WebApps/mysite/mysite/wsgi.py

I further created a file /Library/Server/Web/Config/apache2/webapps/com.example.mysite.wsgi.plist with the following content:

<?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.example.mysite.wsgi</string>
        <key>displayName</key>
        <string>Python "My Site" app</string>
        <key>launchKeys</key>
        <array/>
        <key>proxies</key>
        <dict/>
        <key>installationIndicatorFilePath</key>
        <string>/Library/Server/Web/Data/WebApps/mysite/mysite/wsgi.py</string>
        <key>includeFiles</key>
        <array>
                <string>/Library/Server/Web/Config/apache2/httpd_mysite.conf</string>
        </array>
        <key>requiredModuleNames</key>
        <array>
                <string>wsgi_module</string>
        </array>
</dict>
</plist>

The file com.example.mysite.wsgi.plist was adapted from com.apple.webapp.wsgi.plist and httpd_mysite.conf adapted from httpd_wsgi.conf. Both these files are used to run the "standalone" python application successfully when configured through the server manager.

I then created a site with the server manager, confirmed my application was in the list of web applications. However, when I visit http://example.com/mysite I get a 500 error. The logs has the following entries (IP addresses changed to 1.2.3.4 for privacy reasons):

[Sat Sep 01 21:49:17 2012] [warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Sat Sep 01 21:49:17 2012] [notice] Apache/2.2.22 (Unix) PHP/5.3.13 with Suhosin-Patch mod_wsgi/3.3 Python/2.7.2 mod_fastcgi/2.4.6 mod_ssl/2.2.22 OpenSSL/0.9.8r DAV/2 configured -- resuming normal operations
[Sat Sep 01 21:50:13 2012] [error] [client 1.2.3.4] (8)Exec format error: exec of '/Library/Server/Web/Data/WebApps/mysite/mysite/wsgi.py' failed
[Sat Sep 01 21:50:13 2012] [error] [client 1.2.3.4] Premature end of script headers: wsgi.py

It doesn't seem that the WSGI module is handling the request, but instead, the request may be processed using FCGI. However, the log indicates that mod_wsgi/3.3 was loaded.

When I created a standard Python application that looks as follows:

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

And update the files to point to /Library/Server/Web/Data/WebApps/helloworld.wsgi rather than /Library/Server/Web/Data/WebApps/mysite/mysite/wsgi.py then "Hello World" is displayed. I therefore assume that wsgi is correctly configured and able to execute applications and that something else is wrong with my setup.

解决方案

Some Apache configurations with distros map .py to either CGI or FASTCGI and this will conflict with mod_wsgi. This is why mod_wsgi recommends using a .wsgi extension. So, rename 'wsgi.py' to 'site.wsgi' and then use 'site.wsgi' in the WSGIScriptAlias.

BTW, can you confirm that there is a precompiled mod_wsgi.so shipped with Mountain Lion server.

这篇关于如何在OS X Server上部署django应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆