uwsgiとnginxを使って、複数のアプリを公開
社内で、開発環境や、ステージングなどを同じ環境で、URL分けて使いたい
とか
個人プロジェクト同一URLだけど、プロジェクトとしては分けて開発してる
とか
ポートを分けないで、サーバ内で振り分ける場合の設定についてのメモ
nginx.conf
http {
...
server {
listen 80;
server_name localhost;
# 下記は、http://xxxxxxxx/app/にアクセスされることを想定
location /app/ {
include uwsgi_params;
uwsgi_pass unix:/tmp/uwsgi.sock;
}
...
uwsgi.ini
[uwsgi]
# 下記は、manage.pyがあるディレクトリ
base = /root/demo
# the base directory (full path)
chdir = %(base)
# 下記にbaseからみた、wsgiファイルを指定(core.wsgiの部分)
module = core.wsgi:application
# 下記にpyenvなどのパスを指定
home = /root/.pyenv/versions/sample
# process-related settings
# master
master = true
# maximum number of worker processes
# デモ用なので1を指定
processes = 1
# the socket (use the full path to be safe
# nginxの設定とあわせてsockファイルが生成されるように指定
socket = /tmp/%n.sock
pidfile= %(base)/pr.pid
# ... with appropriate permissions - may be needed
chmod-socket = 666
# clear environment on exit
vacuum = true
touch-reload = %(base)/.uwsgi_touch
daemonize= /var/log/wsgi.log
# 下記は、settingsの指定が必要な場合のみ追記
env = DJANGO_SETTINGS_MODULE=core.master_settings
上記で作成したiniファイルをオプションで指定して実行
uwsgi --ini /root/sample/core/uwsgi.ini