UWSGI

提供: ArchWiki
2015年12月25日 (金) 16:11時点におけるKusanaginoturugi (トーク | 投稿記録)による版 (→‎サービスの起動: 英語版より記述を追加)
ナビゲーションに移動 検索に移動

Uwsgi は高速で自己回復機能のある、開発者とシステム管理人に優しいアプリケーションコンテナサーバーです。C だけで書かれています。

インストール

公式リポジトリuwsgi パッケージをインストールしてください。パッケージをコンパクトにするために、プラグインは付属していません。外部プラグインは別にインストールする必要があります。C で書かれているためとても効率的なソフトウェアです。gunicorn など Python で書かれた代替も存在しますが、どうしても動作は遅くなってしまいます。

サービスの起動

ノート: In the most simple configuration each application (i.e. python application) will get its own instance of uwsgi service.

Before uwsgi service can be enabled/started a configuration file with the same name must be created within /etc/uwsgi/

When reading following lines assume that /etc/uwsgi/helloworld.ini was created.
この記事あるいはセクションで使われている用語や表現には問題が存在します。
議論: does not comply with Help:Style#systemd units operations (議論: トーク:UWSGI#)

スタートアップ時にデフォルトで uwsgi サービスを有効にするには、次を実行:

# systemctl enable uwsgi@helloworld

これで /etc/uwsgi/helloworld.ini 設定されたアプリケーションのサービスが有効になります。また、以下のコマンドを使ってソケットインターフェイスで有効にすることも可能です:

# systemctl enable uwsgi@helloworld.socket

もしくは、Emperor モード サービスを実行することができます。このモードを使うと uwsgi インスタンスで (emperor と呼ばれる) メインスーパーバイザーを使って様々なアプリ (vassal と呼ばれます) が動くようになります。有効にするには、次を入力:

# systemctl enable emperor.uwsgi

ソケットを使うこともできます:

# systemctl enable emperor.uwsgi.socket

Emperor の設定は /etc/uwsgi/emperor.ini にあります。

設定

/etc/uwsgi/ 内のファイルを編集することで設定ができます。パッケージに含まれているビルドファイルは /etc/uwsgi/archlinux.ini に存在します。

詳しくは uwsgi のドキュメント を見て下さい。

アプリケーションの設定

以下は python をサポートするシンプルな例です。pacman で community リポジトリから uwsgi-plugin-python または uwsgi-plugin-python2 プラグインをインストールする必要があります。

[uwsgi]
chdir = /srv/http/helloworld
module = helloworld
plugins = python

以下のような構文を使うことで uwsgi を別個に実行することも可能です:

uwsgi --socket 127.0.0.1:3031 --plugin python2 --wsgi-file ~/foo.py --master --processes 4 --threads 2 --stats 127.0.0.1:9191 --uid --gid

上記のコマンドを root で実行するのは止めてください。

Nginx の設定
location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;
    include uwsgi_params;
    # uwsgi_pass unix:/var/run/uwsgi/helloworld.sock;
    uwsgi_pass 127.0.0.1:3031;
}

参照