django:mod_wsgi:apache2で動かす on Debian Lenny

mod_wsgiのインストール

deb09:~# aptitude install libapache2-mod-wsgi
Reading package lists… Done
Building dependency tree
Reading state information… Done
Reading extended state information
Initializing package states… Done
Reading task descriptions… Done
The following NEW packages will be installed:
  libapache2-mod-wsgi
0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 104kB of archives. After unpacking 307kB will be used.
Writing extended state information… Done
Get:1 http://ftp.jp.debian.org lenny/main libapache2-mod-wsgi 2.3-1 [104kB]
Fetched 104kB in 0s (287kB/s)
Selecting previously deselected package libapache2-mod-wsgi.
(Reading database … 60323 files and directories currently installed.)
Unpacking libapache2-mod-wsgi (from …/libapache2-mod-wsgi_2.3-1_i386.deb) …
Setting up libapache2-mod-wsgi (2.3-1) …
Reloading web server config: apache2.
Reading package lists… Done
Building dependency tree
Reading state information… Done
Reading extended state information
Initializing package states… Done
Writing extended state information… Done
Reading task descriptions… Done

apache2の設定

hdknr@deb09:~/djangocamp/trunk$ mkdir -p apache2

hdknr@deb09:~/djangocamp/trunk$ mkdir -p apache2/logs

hdknr@deb09:~/djangocamp/trunk$ mkdir -p apache2/www

hdknr@deb09:~/djangocamp/trunk$ cd apache2/

hdknr@deb09:~/djangocamp/trunk/apache2$ vi httpd.conf

<VirtualHost *:80>
    ServerAdmin webmaster@debian.hdknr
    DocumentRoot /home/hdknr/djangocamp/trunk/apache2/www
    ServerName mysite.hdknr.vpc:80

     ErrorLog /home/hdknr/djangocamp/trunk/apache2/logs/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.

     LogLevel warn

     CustomLog /home/hdknr/djangocamp/trunk/apache2/logs/access.log combined

</VirtualHost>

hdknr@deb09:~/djangocamp/trunk/apache2$ vi www/index.html

<html>
<body>
mysite.hdknr.vpc
</body>
</html>

hdknr@deb09:~/djangocamp/trunk/apache2$ more www/inidex.html
<html>
<body>
mysite.hdknr.vpc
</body>
</html>

hdknr@deb09:~/djangocamp/trunk/apache2$ sudo ln -s /home/hdknr/djangocamp/trunk/apache2/httpd.conf /etc/apache2/sites-enabled/mysite.hdknr.vpc.conf

hdknr@deb09:~/djangocamp/trunk/apache2$ sudo /etc/init.d/apache2 restart
Restarting web server: apache2 … waiting .

Windows Vistaでアクセスできるようにして確認

C:\Windows\System32\drivers\etc>find "hdknr.vpc" hosts

———- HOSTS
192.168.250.111 hdknr.vpc mysite.hdknr.vpc

WS000093

“apache2 settings for mysite.hdknr.vpc”にコミット

hdknr@deb09:~/djangocamp/trunk$ hg add apache2
adding apache2/httpd.conf
adding apache2/logs/access.log
adding apache2/logs/error.log
adding apache2/www/index.html

hdknr@deb09:~/djangocamp/trunk$ cd apache2/

hdknr@deb09:~/djangocamp/trunk/apache2$ hg commit -u hdknr -m "apache2 settings for mysite.hdknr.vpc"

hdknr@deb09:~/djangocamp/trunk/apache2$ hg push
pushing to ssh://hg@bitbucket.org/hdknr/djangocamp/
searching for changes
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 1 changesets with 5 changes to 5 files
remote: bb/acl: hdknr is allowed. accepted payload.
remote: quota: 61.9 KB in use, 150.0 MB available (0.04% used)

mysite.wsgiを作る

hdknr@deb09:~/djangocamp/trunk$ vi mysite.wsgi

import sys
import os
sys.path.append('/home/hdknr/djangocamp/mysite')

os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

apache2にmysite.wsgiを読むように設定

hdknr@deb09:~/djangocamp/trunk$ vi apache2/httpd.conf

hdknr@deb09:~/djangocamp/trunk$ sudo /etc/init.d/apache2 restart
Restarting web server: apache2 … waiting .

エラー

hdknr@deb09:~/djangocamp/trunk$ tail -f apache2/logs/error.log
[Sun Feb 22 03:09:12 2009] [error] [client 192.168.250.2] Target WSGI script not found or unable to stat: /home/hdknr/djangocamp/mysite.wsgi

httpd.confのパスが間違っていたのと、sys.path.append(‘/home/hdknr/djangocamp/trunk/’)にしてないので、500エラーが出ていた。

httpd.confとmysite.wsgiを修正して再確認。http://mysite.hdknr.vpc/admin/

WS000094

run under mod_wsgi にコミット。

hdknr@deb09:~/djangocamp/trunk$ hg add mysite.wsgi
hdknr@deb09:~/djangocamp/trunk$ hg commit -u hdknr -m "run under mod_wsgi"
hdknr@deb09:~/djangocamp/trunk$ hg push
pushing to ssh://hg@bitbucket.org/hdknr/djangocamp/
searching for changes
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 1 changesets with 4 changes to 4 files
remote: bb/acl: hdknr is allowed. accepted payload.
remote: quota: 63.8 KB in use, 150.0 MB available (0.04% used)

CSSが読み込めない問題は、

Alias /media/ /usr/share/python-support/python-django/django/contrib/admin/m
edia/

を追加してとりあえずしのぐ(“add Alias /media/ for CSS”)。実際は運用状況に応じて対応。

WS000095

カテゴリー: 未分類 パーマリンク

コメントを残す

以下に詳細を記入するか、アイコンをクリックしてログインしてください。

WordPress.com ロゴ

WordPress.com アカウントを使ってコメントしています。 ログアウト / 変更 )

Twitter 画像

Twitter アカウントを使ってコメントしています。 ログアウト / 変更 )

Facebook の写真

Facebook アカウントを使ってコメントしています。 ログアウト / 変更 )

Google+ フォト

Google+ アカウントを使ってコメントしています。 ログアウト / 変更 )

%s と連携中