7
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Django - Apache mod_wsgi virtualhost デプロイ

Last updated at Posted at 2013-04-12

Django - Apache mod_wsgi virtualhost デプロイ

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

ディレクトリ構成

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

7
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?