・ Web系SE募集 (技術開発部開発系エンジニア・Java/Tomcat 420万円~750万円)
   ・ 社内SE募集 (業務系システムの開発・社内イントラ)

"Hello, world!"の最近のブログ記事

参考:Integration With Pylons


$ paster create --template=pylons pylons_with_mod_wsgi

$ cd pylons_with_mod_wsgi/

$ paster controller hello

$ cat /home/httpd/vhost/pylons/pylons_with_mod_wsgi/pylons_with_mod_wsgi/controllers/hello.py
import logging

from pylons_with_mod_wsgi.lib.base import *

log = logging.getLogger(__name__)

class HelloController(BaseController):

def index(self):
# Return a rendered template
# return render('/some/template.mako')
# or, Return a response
return 'Hello World. - Pylons with mod_wsgi'


$ cp development.ini development_apache.ini

$ diff development.ini development_apache.ini
7c7
< debug = true
---
> debug = false
mod_wsgi用環境作成
$ mkdir apache

$ cp pylons_with_mod_wsgi/__init__.py apache/

$ cat apache/pylons.wsgi
import os, sys
sys.path.append('/home/httpd/vhost/pylons/pylons_with_mod_wsgi')
#os.environ['PYTHON_EGG_CACHE'] = '/home/httpd/vhost/pylons/python-eggs'
from paste.deploy import loadapp
application = loadapp('config:/home/httpd/vhost/pylons/pylons_with_mod_wsgi/development_apache.ini')

$ tree apache/
apache/
|-- __init__.py
`-- pylons.wsgi

Apacheのconfファイル
LoadModule wsgi_module        modules/mod_wsgi.so

WSGIScriptAlias / "/home/httpd/vhost/pylons/pylons_with_mod_wsgi/apache/pylons.wsgi"

<Directory         /home/httpd/vhost/pylons/pylons_with_mod_wsgi/apache>
  Order allow,deny
  Allow from all
</Directory>
作業場所
$ pwd
/home/httpd/vhost/django
startproject
$ django-admin.py startproject django_with_wsgi
作られたファイル
$ tree django_with_wsgi/
django_with_wsgi/
|-- __init__.py
|-- manage.py
|-- settings.py
`-- urls.py
mod_wsgi用環境作成
$ mkdir django_with_wsgi/apache
$ cp django_with_wsgi/__init__.py django_with_wsgi/apache/
$ cat > django_with_wsgi/apache/django.wsgi
import os, sys

sys.path.append('/home/httpd/vhost/django')

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

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()
新たに作られたファイルを確認
$ tree django_with_wsgi/
django_with_wsgi/
|-- __init__.py
|-- apache
| |-- __init__.py
| `-- django.wsgi
|-- manage.py
|-- settings.py
`-- urls.py
ページを作る
$ cd django_with_wsgi/
$ python manage.py startapp hello
hello/views.pyを編集
$ cat hello/views.py
# Create your views here.
from django.http import HttpResponse

def index(request):
    return HttpResponse("Hello, world.  Django with mod_wsgi")
urls.py を修正
$ cat urls.py
from django.conf.urls.defaults import *

urlpatterns = patterns('',
(r'^hello/$', 'django_with_wsgi.hello.views.index'),
)
◆ 複数のDjangoを設定する場合
Apache confファイル設定
LoadModule wsgi_module        modules/mod_wsgi.so

WSGIScriptAliasMatch ^/([^/]+) /home/httpd/vhost/django/$1/apache/django.wsgi

<DirectoryMatch ^/home/httpd/vhost/django/([^/]+)/apache>
    Order deny,allow
    Allow from all
</DirectoryMatch>
Apache 再起動
$ sudo /usr/local/apache2/bin/apachectl restart

アクセス確認
$ curl http://localhost/django_with_wsgi/hello/
Hello, world.  Django with mod_wsgi
◆ 一つだけDjangoを設定する場合
Apache confファイル設定
WSGIScriptAlias / "/home/httpd/vhost/django/django_with_wsgi/apache/django.wsgi"

<Directory   /home/httpd/vhost/django/django_with_wsgi/apache>
  Order allow,deny
  Allow from all
</Directory>
Apache 再起動
$ sudo /usr/local/apache2/bin/apachectl restart

アクセス確認
$ curl http://localhost/hello/
Hello, world.  Django with mod_wsgi

$ rails rails_with_passenger

$ script/generate controller helloworld index


$ cat app/views/helloworld/index.html.erb

Helloworld#index

Rails with mod_rails

Find me in app/views/helloworld/index.html.erb

Apache 設定ファイル
LoadModule passenger_module   /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/mod_passenger.so
PassengerRoot                 /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3
PassengerRuby                 /usr/bin/ruby
VirtualHost とかに
DocumentRoot /home/httpd/vhost/rails/rails_with_passenger/public
<Directory   /home/httpd/vhost/rails/rails_with_passenger/public>
  Order allow,deny
  Allow from all
</Directory>
RailsBaseURI /
$ curl "http://localhost/helloworld"

Helloworld#index

Rails with mod_rails

Find me in app/views/helloworld/index.html.erb

このアーカイブについて

このページには、過去に書かれたブログ記事のうち"Hello, world!"カテゴリに属しているものが含まれています。

前のカテゴリは さくらのレンタルサーバです。

次のカテゴリは.netです。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。