Waitress

WaitressはPythonだけで実装されたWSGIサーバです。 `Waitress`_ is a pure Python WSGI server.

  • 容易に設定できます。 It is easy to configure.

  • Windowsを直接サポートします(訳注: WSLを使わなくても実行できます)。 It supports Windows directly.

  • 追加の依存対象やコンパイル処理が不要であるため、インストールが容易です。 It is easy to install as it does not require additional dependencies or compilation.

  • ストリーミングのリクエストはサポートせず、リクエストのデータ全体が常にバッファされます。 It does not support streaming requests, full request data is always buffered.

  • マルチスレッドを使った1つのプロセスのworkerを使用します。 It uses a single process with multiple thread workers.

このページはWaitressを実行する基本について説明します。そのドキュメントとwaitress-serve --help(の出力)を読み、どの目玉機能(feature)が利用できるか理解しておいてください。 This page outlines the basics of running Waitress. Be sure to read its documentation and ``waitress-serve --help`` to understand what features are available.

インストール Installing

virtualenvを作成し、アプリケーションをインストールし、それからwaitressをインストールします。 Create a virtualenv, install your application, then install ``waitress``.

$ cd hello-app
$ python -m venv venv
$ . venv/bin/activate
$ pip install .  # install your application
$ pip install waitress

実行 Running

waitress-serveのただ一つ必要な引数は、Flaskアプリケーションをどのように読み込むかをwaitressに伝えます。記法は{module}:{app}です。moduleは、自分のアプリケーションがあるモジュールの、ドット(「.」)で分けられたimport名です。appはアプリケーションが設定されている変数です。もしapp factoryパターンを使っている場合、代わりに--call {module}:{factory}を使ってください。 The only required argument to ``waitress-serve`` tells it how to load your Flask application. The syntax is ``{module}:{app}``. ``module`` is the dotted import name to the module with your application. ``app`` is the variable with the application. If you're using the app factory pattern, use ``--call {module}:{factory}`` instead.

# equivalent to 'from hello import app'
$ waitress-serve hello:app --host 127.0.0.1

# equivalent to 'from hello import create_app; create_app()'
$ waitress-serve --call hello:create_app --host 127.0.0.1

Serving on http://127.0.0.1:8080

--hostオプションは(上記の例では)サーバをローカルの127.0.0.1だけに結びつけ(bind)します。 The ``--host`` option binds the server to local ``127.0.0.1`` only.

各リクエストのログは表示されず、ただerrorだけが表示されます。ログ処理(loggin)はコマンドラインではなくPythonのインタフェースを通して設定します(訳注: Pythonの標準モジュールであるlogginモジュールを使って設定します)。 Logs for each request aren't shown, only errors are shown. Logging can be configured through the Python interface instead of the command line.

外部への結び付け(Binding Externally) Binding Externally

アプリケーションのコードがrootとして走るようになり、安全ではなくなるため、Waitressはrootとして走らせないようにするべきです。しかしながら、これはポート80や443に結びつけ(bind)出来なくなることを意味します(訳注: 一般的なLinuxでは、およそ1000より小さなポート番号は、セキュリティ対策のためroot権限を持たないプログラムではbindできないようになっており、従ってroot権限がないWSGIサーバではHTTPやHTTPSで標準的に使われる80や443番ポートでリクエストを受け付けられないことになります)。代わりに、nginxまたはApache httpdのようなリバースプロキシをWaitressの前面に使うべきです。 Waitress should not be run as root because it would cause your application code to run as root, which is not secure. However, this means it will not be possible to bind to port 80 or 443. Instead, a reverse proxy such as :doc:`nginx` or :doc:`apache-httpd` should be used in front of Waitress.

外部からアクセスできる全てのIPアドレスのroot権限不要なポートは、--hostオプションを指定しないことで結び付け(bind)できます。これは、リバースプロキシを用意しているときは行わないでください、さもなければリバースプロキシを迂回することが可能になります。 You can bind to all external IPs on a non-privileged port by not specifying the ``--host`` option. Don't do this when using a revers proxy setup, otherwise it will be possible to bypass the proxy.

0.0.0.0はアクセスするには適切なアドレスではないため、ブラウザでは具体的なIPアドレスを使うべきです。 ``0.0.0.0`` is not a valid address to navigate to, you'd use a specific IP address in your browser.