0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WEBサーバーとアプリケーションサーバーの違い

Posted at

Rails で開発してる中でこの2つのサーバーの違いがいまいち理解できてなかったので、調べた内容をまとめました。

Webサーバーとは

ユーザーからのリクエストを最初に受け取り、以下の役割を担います:

機能 説明
静的ファイル配信 画像・CSS等を直接配信
リバースプロキシ 動的コンテンツをアプリケーションサーバーに転送
SSL終端処理 HTTPS通信の暗号化・復号化
負荷分散 複数のアプリケーションサーバー(Puma等)へのリクエスト分散

代表的なWebサーバー

  • Nginx
  • Apache

アプリケーションサーバーとは

Webサーバーから送られてきたリクエストを、Rack規格に従ってRailsアプリケーションに渡し処理を行います。

開発環境では、rails serverで起動するPumaがアプリケーションサーバーとして単体で動いています。
本番環境では、Webサーバーを手前に配置することが多いです。
Webサーバーがあることで、静的コンテンツを素早く配信したり、複数のリクエストを効率的にさばけるようになります。

代表的なアプリケーションサーバー

  • Puma
  • Unicorn

Rackとは

アプリケーションサーバーとRailsが話せる共通言語(ルール)のようなものです。

Rackのメリット

Rackがあることで、Rails側のコードを変更することなく
どのアプリケーションサーバー(Puma/Unicorn等)でも動かすことができます。

また、Rails以外のフレームワーク(Sinatraなど)でも同様で、
Rackに準拠していればフレームワークとアプリケーションサーバーを
自由に組み合わせられるようになります。

全体の処理の流れ

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?