Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

Django - Apache mod_wsgi virtualhost デプロイ

More than 5 years have passed since last update.

Django - Apache mod_wsgi virtualhost デプロイ

メモとして残しておくけど、下記URLのBackliftってサービスで簡単に覚えれるかも。
あとDjangoのバージョンでディレクトリ構造変わってるからそこは要修正。

http://jp.techcrunch.com/2013/04/11/20130410yc-backlift-launch/

ディレクトリ構成

sample
      |-wsgi
         |-dispatch.wsgi
      |-src
          |-sample
               |-settings.py
               |- ・・・

dispatch.wsgi

#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import site
import sys
sys.stdout = sys.stderr

PROJECT_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))

# Add the virtual Python environment site-packages directory to the path
site.addsitedir(os.path.join(PROJECT_ROOT, 'python', 'lib', 'python2.7', 'site-packages'))

# Avoid ``[Errno 13] Permission denied: '/var/www/.python-eggs'`` messages
os.environ['PYTHON_EGG_CACHE'] = os.path.join(PROJECT_ROOT, 'wsgi', 'egg-cache')

#If your project is not on your PYTHONPATH by default you can add the following
sys.path.append(os.path.join(PROJECT_ROOT, 'src', 'sample'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

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

sites-availableに下記ファイルを配置

sample

<VirtualHost *:80>
    ServerName サーバー名

    # Log Files
    ErrorLog /var/log/apache2/sample.error-lostquery.log
    CustomLog /var/log/apache2/sample.access-lostquery.log combined

    RewriteEngine On
    RewriteCond  %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
    RewriteRule  .*robots\.txt$          ~/sample/www/robots.txt [L]

    Alias /www/ ~/sample/www/

    <Directory ~/sample/www>
    Order deny,allow
    Allow from all
    </Directory>

    # Setup mod_wsgi
    WSGIScriptAlias / ~/sample/wsgi/dispatch.wsgi

    <Directory ~/sample/wsgi>
     Order deny,allow
     Allow from all
    </Directory>
 </VirtualHost>

Apacheでサイト有効化してから、restart

bukowski1920
Javaを中心に開発していますが、pythonが好きなプログラマーです。 Google+にまともに紹介文書いてます。 https://plus.google.com/+NozO_Plus/about Twitter https://twitter.com/bukowski1920
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away