Apache httpd

Apache httpdは高速な、製品レベルのHTTPサーバです。本番環境への展開(Deployment to Production)のリストにあるWSGIサーバのひとつを使って自分のアプリケーションを提供するとき、その前面に専用のHTTPサーバを置くことは、しばしば良いこともしくは必要なことになります。この「リバースプロキシ」は受信リクエスト、TLS、その他のセキュリティおよび性能に関することをWSGIサーバよりもうまく処理できます。 `Apache httpd`_ is a fast, production level HTTP server. When serving your application with one of the WSGI servers listed in :doc:`index`, it is often good or necessary to put a dedicated HTTP server in front of it. This "reverse proxy" can handle incoming requests, TLS, and other security and performance concerns better than the WSGI server.

httpd(訳注: Apache httpdのこと)はシステムのパッケージ管理ツール(system package manager)もしくはWindowsではビルド済みの実行ファイルを使ってインストールできます。httpdのインストールおよび実行自体はこのドキュメントの範囲外です。このページは自分のアプリケーションのプロキシになるようhttpdを設定する基本について説明します。httpdのドキュメントを呼んでどの目玉機能(feature)が利用可能か理解しておいてください。 httpd can be installed using your system package manager, or a pre-built executable for Windows. Installing and running httpd itself is outside the scope of this doc. This page outlines the basics of configuring httpd to proxy your application. Be sure to read its documentation to understand what features are available.

ドメイン名 Domain Name

ドメイン名の取得と設定は、このドキュメントの範囲外です。大概は、registrar(訳注: ドメイン名の登録・管理をしている団体のようなもの)からドメイン名を購入し、ホスティング事業者(hosting provider)のサーバ領域に支払い、そしてそれからホスティング事業者のDNSサーバが自分のregistrarを指すようにします。 Acquiring and configuring a domain name is outside the scope of this doc. In general, you will buy a domain name from a registrar, pay for server space with a hosting provider, and then point your registrar at the hosting provider's name servers.

これを模擬するために、Linuxでは/etc/hostsにある、自分のhostsファイル編集することもできます。ドメイン名をローカルのIPに関連付ける行を追加してください。 To simulate this, you can also edit your ``hosts`` file, located at ``/etc/hosts`` on Linux. Add a line that associates a name with the local IP.

最近のLinuxシステムでは、以下の例のように.localhostで終わるドメイン名はすべて、hostsファイルにその行を追加することなく扱われるように設定されているかもしれません。 Modern Linux systems may be configured to treat any domain name that ends with ``.localhost`` like this without adding it to the ``hosts`` file.

/etc/hosts
127.0.0.1 hello.localhost

設定(Configuration) Configuration

httpdの設定はLinuxでは/etc/httpd/conf/httpd.confにあります。オペレーティングシステムによっては違う場所かもしれません。ドキュメントを調べてhttpd.confを探してください。 The httpd configuration is located at ``/etc/httpd/conf/httpd.conf`` on Linux. It may be different depending on your operating system. Check the docs and look for ``httpd.conf``.

存在するすべてのDocumentRoot(の設定)を削除するかコメントアウトします。以下の設定行を追加してください。ここでは、WSGIサーバはローカルのhttp://127.0.0.1:8000でリクエストを受け付けていると想定しています。 Remove or comment out any existing ``DocumentRoot`` directive. Add the config lines below. We'll assume the WSGI server is listening locally at ``http://127.0.0.1:8000``.

/etc/httpd/conf/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
ProxyPass / http://127.0.0.1:8000/
RequestHeader set X-Forwarded-Proto http
RequestHeader set X-Forwarded-Prefix /

LoadModule行は既に存在しているかもしれません。もしそうであれば、手作業でそれらを追加する代わりに、それらをコメント化されてない有効な状態にしてください。 The ``LoadModule`` lines might already exist. If so, make sure they are uncommented instead of adding them manually.

それから、自分のアプリケーションがX-Forwardedヘッダーを使うように、Proxyの背後にいることのFlaskへの指示のとおりにします。X-Forwarded-ForX-Forwarded-HostProxyPassによって自動的に設定されます。 Then :doc:`proxy_fix` so that your application uses the ``X-Forwarded`` headers. ``X-Forwarded-For`` and ``X-Forwarded-Host`` are automatically set by ``ProxyPass``.