自作やOSX10.8.1に付属しているものとは異なる種類のPythonを使用せずに、OS X Server 2.0にDjangoアプリケーションをデプロイするにはどうすればよいですか?Djangoアプリケーションでcocoaバインディングを使用していますが、デスクトップマシン(OS X 10.8.1を実行)で自作で動作させるのに問題がありました。したがって、システムにインストールされているバージョンのPythonにアプリケーションをデプロイするリクエスト。
次のOSXServer環境があり、次のものがすでにインストールされています。
- 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
私の最初の試みは、空のWebサイトをデプロイすることです。それが成功したら、本番環境で使用する実際のアプリケーションをデプロイします。プロジェクトは/Library/Server/Web/Data/WebApps/mysite/
、次のコマンドを使用して作成されました
django-admin.py startproject mysite
次のコマンドを使用してアプリケーションを実行しました。アプリケーションが稼働していることを確認しただけです。標準の「効いた!」です。プロジェクトを最初に作成したときのページ。
python manage.py runserver 8080
/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.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アプリケーションを正常に実行するために使用されます。
次に、サーバーマネージャーを使用してサイトを作成し、自分のアプリケーションがWebアプリケーションのリストに含まれていることを確認しました。ただし、http://example.com/mysiteにアクセスすると、500エラーが発生します。ログには次のエントリがあります(プライバシー上の理由からIPアドレスは1.2.3.4に変更されています)。
[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
がロードされたことが示されます。
次のような標準のPythonアプリケーションを作成したとき:
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]
そして、「Hello World」が表示されるの/Library/Server/Web/Data/WebApps/helloworld.wsgi
ではなく、ポイントするようにファイルを更新します。/Library/Server/Web/Data/WebApps/mysite/mysite/wsgi.py
したがって、wsgiが正しく構成され、アプリケーションを実行できること、およびセットアップに問題があると想定しています。