Django を mod_wsgi で Apache 上にデプロイする

* 公式ドキュメント読め
https://docs.djangoproject.com/ja/1.9/howto/deployment/wsgi/modwsgi/

* Apache 再起動しろ

$ sudo apachectl restart

* httpd.conf を編集しろ
- static ファイルのパスをエイリアスする
- wsgi モジュールのロード
- WSGIScriptAlias, WSGIPythonPath の設定
- アクセス権限設定
- db のファイルパーミッション変更
   $ chmod 777 -R db.sqlite3

# Added @ 2016/05/28
Alias /static/ /path/to/project/mysite/polls/static/
LoadModule wsgi_module /path/to/project/venv/lib/python3.5/site-packages/mod_wsgi/server/mod_wsgi-py35.cpython-35m-darwin.so
WSGIScriptAlias /wsgi /path/to/project/mysite/mysite/wsgi.py
WSGIPythonPath /path/to/project/venv/lib/python3.5/site-packages/:/path/to/project/mysite
<Directory /path/to/project/mysite/polls/static>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
 
    <Files wsgi.py>
    Require all granted
    </Files>
</Directory>
<Directory /path/to/project/mysite/mysite>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory> 

* サーバーが吐くエラー読め
$ tail -f /var/log/apache2/error_log 



* デプロイ手順メモ
$ git clone git@github.com:ks6088ts/sandbox.git -b feature/django
$ sandbox/

$ source setup.sh 
# project/settings.py の STATIC_ROOT を定義、STATICFILES_DIRSの static を削除した後、 python manage.py collectstatic
$ sudo apachectl restart
http://localhost/wsgi/admin/ にアクセス

コメント

このブログの人気の投稿

Callback関数を知らん人がまず理解すべきことのまとめ。

C言語でBluetoothスタックを叩きたい人のBluetooth開発入門その1

C++プログラミング入門(1) // 倉庫番プログラムの実装