如何在 OS X Server 上部署 django 应用程序? [英] How does one deploy a django application on OS X Server?
问题描述
如何在 OS X Server 2.0 上部署 Django 应用程序而不使用自制软件或与 OS X 10.8.1 附带的不同风格的 Python?我在 Django 应用程序中使用可可绑定,但在我的台式机(运行 OS X 10.8.1)上使用自制软件时遇到了麻烦;因此请求在系统安装的 Python 版本上部署应用程序.
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.
我有以下 OS X Server 环境,并且已经安装了以下内容:
I have the following OS X Server environment, with the following already installed:
- OS X 10.8.1
- OS X 服务器 2.0
- Python 2.7.2
- Apache 2.2.22
Django 1.4.1 是使用以下命令安装的:
Django 1.4.1 was installed using the following command:
sudo easy_install django
我的第一次尝试是部署一个空网站,一旦成功,就部署一个真正的应用程序以用于生产.该项目是使用以下命令在 /Library/Server/Web/Data/WebApps/mysite/
创建的
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
然后我创建了一个文件 /Library/Server/Web/Config/apache2/httpd_mysite.conf
,内容如下:
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
我进一步创建了一个文件 /Library/Server/Web/Config/apache2/webapps/com.example.mysite.wsgi.plist
,内容如下:
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>
文件 com.example.mysite.wsgi.plist
改编自 com.apple.webapp.wsgi.plist
和 httpd_mysite.conf
改编自 httpd_wsgi.conf
.通过服务器管理器配置后,这两个文件都用于成功运行独立"python 应用程序.
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.
然后我用服务器管理器创建了一个站点,确认我的应用程序在 Web 应用程序列表中.但是,当我访问 http://example.com/mysite 时,出现 500 错误.日志包含以下条目(出于隐私原因,IP 地址更改为 1.2.3.4):
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
似乎不是 WSGI 模块在处理请求,而是使用 FCGI 处理请求.但是,日志表明 mod_wsgi/3.3
已加载.
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.
当我创建一个如下所示的标准 Python 应用程序时:
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]
并更新文件以指向 /Library/Server/Web/Data/WebApps/helloworld.wsgi
而不是 /Library/Server/Web/Data/WebApps/mysite/mysite/wsgi.py
然后显示Hello World".因此,我假设 wsgi 已正确配置并且能够执行应用程序,并且我的设置存在其他问题.
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.
推荐答案
某些带有发行版的 Apache 配置将 .py 映射到 CGI 或 FASTCGI,这将与 mod_wsgi 冲突.这就是 mod_wsgi 推荐使用 .wsgi 扩展名的原因.因此,将wsgi.py"重命名为site.wsgi",然后在 WSGIScriptAlias 中使用site.wsgi".
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.
顺便说一句,你能确认一下 Mountain Lion 服务器附带了一个预编译的 mod_wsgi.so.
BTW, can you confirm that there is a precompiled mod_wsgi.so shipped with Mountain Lion server.
这篇关于如何在 OS X Server 上部署 django 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!