2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Spring-security+Jetty+ELBでSSLオフロード(SSL終端)

Posted at

やりたいこと

ユーザのブラウザからELBまではhttpsで通信、ELBからアプリケーションサーバまではhttpで通信させる
→ これをWikipedia - SSLオフロード, 英語版 TLS termination proxyと言う。Rails, ngnix, ELBでやったことはあったけど、Springではやったことない。そしてできればHttpsを強制させたい。

Springのソース改変するのは面倒なのでミドルウェア層で解決する。

Tomcatでの設定例

以下のブログポストでTomcatでの設定例がある、詳しくはブログポストを見てほしいが基本的にはserver.xmlの記述を書き換えるだけでよい

  HTTP (80) -----> ELB -----> Tomcat (8080)
HTTPS (443) -----> ELB -----> Tomcat (8080)

これで、ELB経由してるブラウザからはHttpsで全部通信してるようになる。

Jetty9での設定

ここからは自分が調査したところになる、Jettyはバージョンによって内部のクラスが結構変わるので、古いWikiなどを見ると設定が通らないことがある。

最終的にはこの部分をアンコメントすることで、Tomcatと同等の設定ができた。

<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
  ...
  <!-- Uncomment to enable handling of X-Forwarded- style headers -->
  <Call name="addCustomizer">
    <Arg><New class="org.eclipse.jetty.server.ForwardedRequestCustomizer"/></Arg>
  </Call>
</New>

ForwardedRequestCustomizerはロードバランサから送られるX-Forwardedのヘッダがついたリクエストを良しなに処理してくれる。

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?