LoginSignup
2
4

More than 5 years have passed since last update.

【WebSphere Liberty Hints & Tips】デフォルトのホスト設定は変える

Last updated at Posted at 2017-12-18

はじめに

製品版のWebSphere LibertyもOSS版のOpen Libertyも同じです。
製品インストール時のserver.xmlのデフォルトでは、アプリケーションが動くエンドポイントがlocalhostのみになっています。これをうっかり忘れてるとアプリを動かしてるマシンのIP/Host名でアクセスしようとしても接続拒否に遭うので、その時の備忘録です。

設定方法

  1. アプリケーションはdropinsディレクトリに入っていて動いてるものとします。
  2. デフォルトのserver.xmlを確認します。httpEndpointを見てみると、idとhttpPortとhttpsPortがそれぞれデフォルトで設定されています。hostは設定されていませんが、裏ではデフォルトでlocalhostが設定されています。To access...というコメントに注意書きがありますね、これを読み飛ばすと以下に遭遇します(つまり私は読み飛ばした上にデフォルト値も失念してたというわけです)。。
server.xml
<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">

    <!-- Enable features -->
    <featureManager>
        <feature>jsp-2.3</feature>
    </featureManager>

    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
    <httpEndpoint id="defaultHttpEndpoint"
                  httpPort="9080"
                  httpsPort="9443" />

    <!-- Automatically expand WAR files and EAR files -->
    <applicationManager autoExpand="true"/>

3.このままIPを指定してアプリケーションにアクセスしてみても接続できません。
Kobito.FJS5pn.png

4.curlの結果は以下のとおり接続拒否です。
Kobito.EiQSwK.png

5.localhostではアクセスできます。
Kobito.9YMi5c.png

6.それではserver.xmlの設定変更します。host="*"を追記します。*にすると自マシンで使える全ネットワーク・インターフェースで受け付けるようになりますので、*でなく特定のIP/Hostを指定してもよいです。ちなみにここでJVMの再起動は不要で変更は自動反映されます。便利ですがうっかりミスしないように気をつけましょう。

server.xml
<server description="new server">

    <!-- Enable features -->
    <featureManager>
        <feature>jsp-2.3</feature>
        <feature>localConnector-1.0</feature>
    </featureManager>

    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
    <httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint" host="*"/>

   <!-- Automatically expand WAR files and EAR files -->
   <applicationManager autoExpand="true"/>
</server>

7.再度アプリケーションにアクセスしてみると、今度はアクセスできます。
Kobito.5Hssp0.png

まとめ

localhostだけで動かすことは少ないと思いますので、host=""の設定を忘れずないようにしましょう。。

参考情報

HTTP Endpoint (httpEndpoint)
https://www.ibm.com/support/knowledgecenter/en/SSEQTP_8.5.5/com.ibm.websphere.wlp.doc/ae/rwlp_config_httpEndpoint.html

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