Contents
- 1 Jettyとは
- 2 サーバー構築
- 3 ツール
- 4 設定
- 4.1 各種ファイルについて
- 4.2 プロパティファイル(.ini)
- 4.2.1 初期設定(start.ini)
- 4.2.2 基本設定
- 4.2.3 ログ
- 4.2.4 セキュリティ
- 4.2.5 リライト
- 4.2.6 プロキシ・バランサ
- 4.3 モジュールファイル(.mod)
- 4.4 設定ファイル(.xml)
- 5 Tips
Jettyとは
サーブレットコンテナの一種で、特に機能が限定されている分、軽量であるため、軽量サーブレットコンテナと呼ばれる。
Webサーバ機能も保持しているため、本プロダクトのみで、静的コンテンツも動的コンテンツも扱える。
主に、WebサーバにApacheを用いるまでもない小規模サイトで使用されるが、その軽量さを活かして、高いスループットが求められるWEBサイトでサーブレットコンテナ専用としても使用されている。
Jetty自体もJavaで開発されており、WORAを実現している。
各種URL
- 公式ページ:http://www.eclipse.org/jetty/
- ドキュメント:http://www.eclipse.org/jetty/documentation/9.4.6.v20170531/
サーバー構築
構築環境
- Jetty
9.4.6.v20170531
- OS
CentOS 7.3
- JAVA
8u144
OS設定
ネットワーク
固定IPアドレス割り当て
次のファイルを編集する
# ifcfg-loはループバックインタフェースであるため、触らない vi /etc/sysconfig/network-scripts/ifcfg-<インタフェース名>
以下では例として192.168.0.51/24を割り当てた
BOOTPROTO=static ONBOOT=yes IPADDR=192.168.0.51 NETMASK=255.255.255.0 NETWORK=192.168.0.0 GATEWAY=192.168.0.1
ネットワークを再起動する
systemctl restart network
ip addressコマンドにより、インタフェースが有効になっていることを確認する
これによりホストマシンなどからSSHでログイン可能となる
firewalld
JettyのデフォルトポートはTCP/8080であるが、単体でWEBサーバとして動作させるので、TCP/80を開ける。
接続元IPアドレス制限は行わない。
HTTPを開ける
- 現在ルールが定義されていることを確認
firewall-cmd --permanent --info-service=http
- 現在ルールが適用されていないことを確認する
firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep http
- ルールを適用する
firewall-cmd --add-service=http --zone=public --permanent
- ルールが適用されていることを確認する
firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep http
- 設定を再読み込みして反映させる
firewall-cmd --reload
HTTPSも開ける場合
- 現在ルールが定義されていることを確認
firewall-cmd --permanent --info-service=https
- 現在ルールが適用されていないことを確認する
firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep https
- ルールを適用する
firewall-cmd --add-service=https --zone=public --permanent
- ルールが適用されていることを確認する
firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep https
- 設定を再読み込みして反映させる
firewall-cmd --reload
TCP/8080を開ける場合
- 現在ルールが定義されていないか確認
firewall-cmd --permanent --info-service=jetty
- 新しいルールを定義
firewall-cmd --new-service=jetty --permanent firewall-cmd --service=jetty --add-port=8080/tcp --permanent
- ルールが定義されていることを確認
firewall-cmd --permanent --info-service=jetty
- 現在ルールが適用されていないことを確認する
firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep jetty
- ルールを適用する
firewall-cmd --add-service=jetty --zone=public --permanent
- ルールが適用されていることを確認する
firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep jetty
- 設定を再読み込みして反映させる
firewall-cmd --reload
ホスト名
ホスト名としてjettyを設定する
hostname jetty.corp # 再起動しても有効にする echo jetty.corp > /etc/hostname再ログインすることで有効になる。
Java環境の構築
JDKをインストールする
ダウンロード
今回は2017/08/26時点の最新版「JDK8u144」をダウンロードする。
展開するだけで使用できる圧縮版(jdk-8u144-linux-x64.tar.gz)をダウンロードする。
ダウンロードの前に「Accept License Agreement」ラジオボタンにチェックを入れること。
ダウンロードの際はページに記載のハイパーリンク(http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz)からダウンロードしようとすると、エラーが発生するので、一旦PCでダウンロードを試み、それをキャンセル。
その際ダウンロードを行おうとしたURL(http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz?AuthParam=XXX_XXXXXのようになる)をコピーし、そこから改めてダウンロードする。
※Chromeではダウンロード元URLを取得できない。
※PCにダウンロードしてSCP転送でもよい。
curl -s -O <JDKのURL>
インストール
tar xzfv jdk-*.tar.gz* rm -f jdk-*.tar.gz* mv jdk* /usr/local/ ln -s /usr/local/jdk* /usr/local/jdk
環境変数
環境変数を設定し、パスを通す。
export JAVA_HOME=/usr/local/jdk export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
これによって「java」コマンドが実行できるようになったので、確認する。
java -version
- 実行例
[root@jetty ~]# java -version java version "XXXXX" Java(TM) SE Runtime Environment (build XXX-XXX) Java HotSpot(TM) 64-Bit Server VM (build XXXXXX, mixed mode)
更に再起動・再ログインしても自動で設定されるようにbashrcに設定を追加する
echo "" >> /etc/bashrc echo "# JAVA ENVIRONMENT VARIABLE" >> /etc/bashrc。 echo export JAVA_HOME=/usr/local/jdk >> /etc/bashrc echo export PATH=\$JAVA_HOME/bin:\$PATH >> /etc/bashrc echo export CLASSPATH=.:\$JAVA_HOME/lib/tools.jar:\$JAVA_HOME/lib/dt.jar >> /etc/bashrc
Jettyの構築
ダウンロード
ダウンロードページから最新のものをダウンロードする。
今回ダウンロードするバージョンのリンクはこちら。
curl -s -O http://central.maven.org/maven2/org/eclipse/jetty/jetty-distribution/9.4.6.v20170531/jetty-distribution-9.4.6.v20170531.tar.gz
インストール
インストールは展開して任意の場所に配置するだけである。
tar xzfv jetty-*.tar.gz rm -f jetty-*.tar.gz mv jetty-* /usr/local/`ls | grep jetty-* | sed -e "s/-distribution//g"` ln -s /usr/local/jetty-* /usr/local/jetty cd /usr/local/jetty
インストール確認
インストールできているか確認する。
bin/jetty.sh check
このコマンドを実行した際、インストールしたJavaとJETTYの情報が表示されているか確認しておく。
- 実行例
Jetty NOT running JAVA = /usr/local/jdk/bin/java JAVA_OPTIONS = -Djetty.home=/usr/local/jetty -Djetty.base=/usr/local/jetty -Djava.io.tmpdir=/tmp JETTY_HOME = /usr/local/jetty JETTY_BASE = /usr/local/jetty START_D = /usr/local/jetty/start.d START_INI = /usr/local/jetty/start.ini JETTY_START = /usr/local/jetty/start.jar JETTY_CONF = /usr/local/jetty/etc/jetty.conf JETTY_ARGS = jetty.state=/usr/local/jetty/jetty.state jetty-started.xml JETTY_RUN = /var/run/jetty JETTY_PID = /var/run/jetty/jetty.pid JETTY_START_LOG= /var/run/jetty/jetty-start.log JETTY_STATE = /usr/local/jetty/jetty.state RUN_CMD = /usr/local/jdk/bin/java -Djetty.home=/usr/local/jetty -Djetty.base=/usr/local/jetty -Djava.io.tmpdir=/tmp -jar /usr/local/jetty/start.jar jetty.state=/usr/local/jetty/jetty.state jetty-started.xml
環境変数の追加
環境変数を設定して簡単に使えるようにしておく。
export JETTY_HOME=/usr/local/jetty export PATH=$JETTY_HOME/bin:$PATH
次回ログイン時にも設定されるようにする。
echo "" >> /etc/bashrc echo "# JETTY ENVIRONMENT VARIABLE" >> /etc/bashrc echo "export JETTY_HOME=/usr/local/jetty" >> /etc/bashrc echo "export PATH=\$JETTY_HOME/bin:\$PATH" >> /etc/bashrc
不要ファイルの削除
ドキュメントなど、サーバの実行に不要なファイルは消しておく。
インストールされているファイル
存在するファイルは以下
- README.TXTファイル
簡単に使用方法が書かれている。
拡張子がプレインテキストであるが、HTMLファイルである。
- VERSION.txtファイル
- binディレクトリ
Jettyを管理するスクリプトjetty.shのみがインストールされている。
- demo-base
デモ用のWEBアプリケーションの起点となるディレクトリ
- etcディレクトリ
各拡張機能の設定ファイルが格納されている。
この設定ファイル中でプロパティファイル(start.ini)で具体的な値を設定した場合にそれを設定し、そうでない場合はデフォルト値を適用する、といった汎用的な定義を行っている。
その為、このディレクトリ内のファイルは原則変更不要である。
なお、各パラメータのデフォルト値はここで定義されるが、読み込まれる設定ファイルによって、デフォルト値が異なる場合がある。
- libディレクトリ
jarファイルのほか、Linux用のスタティックライブラリ(.so)等が少数インストールされている。
- license-eplv10-aslv20.htmlファイル
ライセンス情報のHTMLファイル
- logsディレクトリ
ログ出力ディレクトリ。インストール直後は空である。
- modulesディレクトリ
拡張モジュールを使用する際の構成情報ファイル(.mod)が主に格納されている。
このファイルはテキストファイルである。
Jettyはjarファイルを直接指定して機能を有効化するのではなく、このモジュールファイルを指定して読み込ませることで、特定の拡張機能を有効にする。
その為、libディレクトリにライブラリを配置しただけでは自動でロードされない。
モジュール定義ファイルは原則変更不要である。
モジュール定義ファイル中には
- notice.htmlファイル
使用条項が記載されている。
- resourcesディレクトリ
インストール直後は空である。
- start.iniファイル
プロパティ形式の設定ファイル
- start.jarファイル
JettyのMainのjarファイル。
binディレクトリの管理スクリプトも内部でこのファイルを呼び出している。
- webappsディレクトリ
デフォルトのWEBアプリケーションのデプロイディレクトリ。
上記のdemo-baseディレクトリのように起点を変更することは可能である。
削除の実行
- ドキュメントファイル
rm -f \ README.TXT \ VERSION.txt \ license* \ notice.html
- デモ
rm -rf demo-base
- webappsディレクトリ内の削除
rm -rf webapps/*
ROOTディレクトリの作成
Jettyはwarファイルなどのウェブアプリケーションのみならず、静的ファイルも設置できる。
静的ファイルは公開ディレクトリ直下のROOTディレクトリに配置する。
今回はインストールディレクトリ直下のwebappsを公開ディレクトリとし、静的ファイルを利用するものとして、ROOTディレクトリを作成する。
mkdir webapps/ROOT
実行ユーザ設定
Jettyを起動するユーザとそのグループを作成する。
- ユーザが存在しないことを確認
cat /etc/passwd | grep jetty
- ユーザ作成
useradd --user-group --no-create-home -d $JETTY_HOME --shell /sbin/nologin jetty
- ユーザが作成されたことを確認
cat /etc/passwd | grep jetty
所有者の変更
ユーザ”jetty”で起動するので所有者を変更しておく
chown jetty:jetty -R /usr/local/jetty*
初期設定
cat > start.ini << EOT --module=server --module=jsp --module=jstl --module=deploy --module=setuid --module=logging-jetty --module=console-capture --module=http jetty.http.port=80 --module=requestlog jetty.requestlog.filenameDateFormat=yyyyMMdd jetty.requestlog.filePath=logs/requestyyyy_mm_dd.log jetty.requestlog.append=true jetty.requestlog.timezone=JST EOT
起動
jetty.sh start &接続確認を行う
curl -s http://localhost/test | head「Error 404 – Not Found.」が返るが、「Powered by Jetty」とあり、Jettyが動作していることがわかる。
停止
jetty.sh stop
サービス登録
systemdのサービスとして登録する。
- サービスファイルを作成する
cat > /etc/systemd/system/jetty.service << EOT [Unit] Description=Jetty Servlet Container & HTTP/HTTPS server After=local-fs.target network.target network-online.target [Service] Type=simple ExecStart=/usr/local/jetty/bin/jetty.sh start & ExecReload=/usr/local/jetty/bin/jetty.sh restart ExecStop=/usr/local/jetty/bin/jetty.sh stop User=jetty [Install] WantedBy=multi-user.target EOT
- サービスを有効化する
systemctl enable jetty
- サービスが有効化されていることを確認する
systemctl list-unit-files --type service --no-pager | grep jetty
- サービスを有効化する
ツール
jetty.sh
- 使用方法
[root@eldorado-of jetty]# jetty.sh Usage: jetty.sh [-d] {start|stop|run|restart|check|supervise} [ CONFIGS ... ] [root@eldorado-of jetty]# java -jar start.jar --help Usage: java -jar start.jar [options...] [properties...] [configs...] The start.jar builds a classpath and executes a main java class with a classloader built from that classpath. By default the start.jar mechanism is configured to start the jetty server, but it can be configured to start any java main class. Command Line Options: --------------------- --help This help / usage information. --version Print the version information for Jetty and dependent jars, then exit. --list-classpath Print the classpath information that will be used to start Jetty --list-config List the resolved configuration that will be used to start Jetty. Output includes: o Java Environment o Jetty Environment o JVM Arguments o Properties o Server Classpath o Server XML Configuration --dry-run Print the command line that the start.jar generates, then exit. This may be used to generate command lines when the start.ini includes -X or -D arguments. --exec Run the generated command line (see --dry-run) in a sub process. This can be used when start.ini contains -X or -D arguments, but creates an extra JVM instance. --exec-properties=<filename> Assign a fixed name to the file used to transfer properties to the sub process. This allows the generated properties file to be saved and reused. Without this option, a temporary file is used. --commands=<filename> Use each line of the file as arguments on the command line. Debug and Start Logging: ------------------------ --debug Enable debug output of the startup procedure. Note: this does not setup debug for Jetty itself. If you want debug for Jetty, configure your logging. http://www.eclipse.org/jetty/documentation/ --start-log-file=<filename> A filename, relative to ${jetty.base}, where all startup output will be sent. This is useful for capturing startup issues where the jetty specific logger has not yet kicked in due to startup configuration errors. Module Management: ------------------ --list-modules List non verbose modules defined by the system. Looking for module files in ${jetty.base}/modules/*.mod and then ${jetty.home}/modules/*.mod Will also list enabled state based on information present on .. o The command line o The ${jetty.base}/start.ini o The ${jetty.base}/start.d/*.ini files --list-modules=<tag>(,<tag>)* List modules by tag. Use '*' for all tags. Prefix a tag with '-' to exclude the tag. The special tag "internal" is always excluded unless it is explicitly included. --list-all-modules List all modules. --module=<modulename>(,<modulename>)* Temporarily enable a module from the command line. Note: this can also be used in the ${jetty.base}/start.ini or ${jetty.base}/start.d/*.ini files. --add-to-start=<modulename>(,<modulename>)* Add the modules to the list of modules enabled at start. Transitive dependencies are followed and dependent modules may also explicitly added. Modules are added to the start by creating an ini file that contains the --module argument and any other parameters defined in the modules ini template. If the directory ${jetty.base}/start.d exists then <modulename>.ini files are created within that directory, otherwise then enabling configuration is appended to the ${jetty.base}/start.ini file. If the ini template contains properties, these may be amended in the generated file by specifying those properties on the command line. Note: not all modules have ini templates and thus may be transitively enabled and not explicitly enabled in a ini file. --update-ini Scan all start.ini and start.d/*.ini files and update any properties with values specified on the command line. e.g. --update-ini jetty.http.port=8888 --create-startd Ensure that a start.d directory exists for use by subsequent --add-to-start=*. If a start.ini file exists it is moved to the start.d directory --write-module-graph=<filename> Create a graphviz *.dot file of the module graph as it exists for the active ${jetty.base}. See http://graphviz.org/ for details on how to post-process this file into the output best suited for your needs. --create-files Create any missing files that are required by initialized modules. This may download a file from the network if the module provides a URL. --skip-file-validation=<modulename>(,<modulename)* Disable the [files] section validation of content in the ${jetty.base} directory for a specific module. Useful for modules that have downloadable content that is being overridden with alternatives in the ${jetty.base} directory. CAUTION: This advanced option is for administrators that fully understand the configuration of their ${jetty.base} and are willing to forego some of the safety checks built into the jetty-start mechanism. --approve-all-licenses Approve all license questions. Useful for enabling modules from a script that does not require user interaction. Startup / Shutdown Command Line: -------------------------------- --stop Send a stop signal to the running Jetty instance. The server must have been started with a STOP.PORT=<port> property set and the stop command must have the same property. Advanced Commands: ------------------ --lib=<classpath> Add arbitrary classpath entries to the the server classpath. --include-jetty-dir=<path> Include an extra jetty directory to use as a source for configuration details. This directory behaves similarly to ${jetty.base} but sits at a layer between ${jetty.base} and ${jetty.home}. This allows for some complex hierarchies of configuration details. --download=<http-uri>|<location> Advanced usage, If the file does not exist at the given location, download it from the given http URI. Notes: location is always relative to ${jetty.base}. you might need to escape the slash "\|" to use this on some environments. Properties: ----------- Properties are used to parameterize: + XML files using the <Property name="pname"/> element + Module files using the ${pname} syntax Properties and System Properties may be set on the command line, in a ini file or in a [ini] section of a module using the following syntax: name=value Set a property that can be expanded in XML files with the <Property> element. name+=value Append value to an existing property value. name+=,value Append value to an existing property value, using a comma separator if needed. name?=value Set a property only if it is not already set. If any of the previous formats is preceded by -D, then a system property is set as well as a start property. Each module may define it's own properties. Start properties defined include: jetty.home=[directory] Set the home directory of the jetty distribution. jetty.base=[directory] Set the jetty configuration directory. This is where the etc, webapps and start files will be looked for. If not found in jetty.base, they are looked for in jetty.home. STOP.HOST=[string] The host to use to stop the running Jetty server (defaults to 127.0.0.1) Required along with STOP.PORT if you want to use the --stop option above. STOP.PORT=[number] The port to use to stop the running Jetty server. Required along with STOP.KEY if you want to use the --stop option above. STOP.KEY=[alphanumeric] The passphrase defined to stop the server. Required along with STOP.PORT if you want to use the --stop option above. STOP.WAIT=[number] The time (in seconds) to wait for confirmation that the running Jetty server has stopped. If not specified, the stopper will wait indefinitely. Use in conjunction with the --stop option. Defaults: --------- Command line arguments can come from any jetty configuration directory (except ${jetty.home}), such as ${jetty.base} and any added jetty directories (see --include-jetty-dir=<path>). The contents of <path>/start.ini and <path>/start.d/*.ini are all used to build up your command line arguments. In case of a conflict, the resolution of who wins, will look like this. 1) <command-line itself> 2) ${jetty.base}/start.ini 3) ${jetty.base}/start.d/*.ini 4) <jetty-dir>/start.ini 5) <jetty-dir>/start.d/*.ini For more information on startup, see the online documentation at http://www.eclipse.org/jetty/documentation/
サブコマンド
start
Jettyをバックグラウンドで実行する。
stopサブコマンドで停止できる。
実行中は下記のパスにPIDファイルが生成される。
/var/run/jetty/jetty.pid
stop
バックグラウンドで実行中のJettyを停止する。
run
Jettyをフォアグラウンドで実行する。
実行後コントロールが復帰しないが、バックグラウンドモードで動作させるとkill以外に停止させる手段がない。
その為、通常はバックグラウンドで起動するstartサブコマンドを使用したほうが良い。
Jetty自体のパラメータ変更などの動作検証をする際に使用するのが良い。
restart
バックグラウンドで実行中のJettyを再起動する。
check
Jettyの動作環境、動作状況を出力する。
supervise
daemontoolsのsuperviseプログラムを使用してプロセス監視を行う際にのみ利用する。
設定
各種ファイルについて
参考:http://www.eclipse.org/jetty/documentation/current/quick-start-configure.html#_jetty_start_configuration_files
Jettyの設定を行うファイルは以下の3つに分かれる。
- プロパティファイル(.ini)
Jettyの起動時に与えられる引数で、起動時に設定すべきものを記述する。
頻繁に設定変更するものではないが、原則設定すべきものである。
- モジュールファイル(.mod)
特定の機能を有効にするための各種設定を行う。
起動時に指定する必要があり、直接モジュールファイルを指定することもできるが、通常はプロパティファイル内にて指定する。
モジュールファイルは内部で設定ファイルを呼び出すほか、必要なライブラリをクラスパスに追加したりする。
有効になるモジュールに対応したプロパティ一覧がコメントとして記載されているので、モジュールを追加する際に参照するとよい。
原則として設定しないが、何らかのモジュールを追加する際に記述する可能性がある。
- 設定ファイル(.xml)
Jettyの起動時にJettyのJavaオブジェクトに対して行う各種の操作を記述する。
文法に従い、インスタンス作成、プロパティ設定、メソッド呼び出しなど、オブジェクトに対して任意の操作を行える。
プロパティファイル(.ini)で特定モジュールを有効にし、設定ファイル(.xml)で詳細な値を設定するという使い方をする。
多くの場合、モジュールに対応する設定ファイル(.xml)がデフォルトで用意されているので、XMLファイルを編集するだけで設定できる。
プロパティファイル(.ini)
プロパティファイルはstart.iniまたはstart.dディレクトリは以下に配置した*.iniファイルによって記述される。
これらのファイルは配置するだけで、自動で起動時にロードされる。
また、起動時のオプションとして与えることもできる。
設定の優先順位は
- 起動オプション
- start.ini
- start.dディレクトリ
である。
同じ優先順位の設定内に同じプロパティを複数書いた場合、最後に指定したものが有効になる。
初期設定(start.ini)
#=========================================================== # Jetty Startup # # Starting Jetty from this {jetty.home} is not recommended. # # A proper {jetty.base} directory should be configured, instead # of making changes to this {jetty.home} directory. # # See documentation about {jetty.base} at # http://www.eclipse.org/jetty/documentation/current/startup.html # # A demo-base directory has been provided as an example of # this sort of setup. # # $ cd demo-base # $ java -jar ../start.jar # #=========================================================== # To disable the warning message, comment the following line --module=home-base-warning # --------------------------------------- # Module: ext # Adds all jar files discovered in $JETTY_HOME/lib/ext # and $JETTY_BASE/lib/ext to the servers classpath. # --------------------------------------- --module=ext # --------------------------------------- # Module: server # Enables the core Jetty server on the classpath. # --------------------------------------- --module=server ### ThreadPool configuration ## Minimum number of threads # jetty.threadPool.minThreads=10 ## Maximum number of threads # jetty.threadPool.maxThreads=200 ## Thread idle timeout (in milliseconds) # jetty.threadPool.idleTimeout=60000 ### Common HTTP configuration ## Scheme to use to build URIs for secure redirects # jetty.httpConfig.secureScheme=https ## Port to use to build URIs for secure redirects # jetty.httpConfig.securePort=8443 ## Response content buffer size (in bytes) # jetty.httpConfig.outputBufferSize=32768 ## Max response content write length that is buffered (in bytes) # jetty.httpConfig.outputAggregationSize=8192 ## Max request headers size (in bytes) # jetty.httpConfig.requestHeaderSize=8192 ## Max response headers size (in bytes) # jetty.httpConfig.responseHeaderSize=8192 ## Whether to send the Server: header # jetty.httpConfig.sendServerVersion=true ## Whether to send the Date: header # jetty.httpConfig.sendDateHeader=false ## Max per-connection header cache size (in nodes) # jetty.httpConfig.headerCacheSize=512 ## Whether, for requests with content, delay dispatch until some content has arrived # jetty.httpConfig.delayDispatchUntilContent=true ## Maximum number of error dispatches to prevent looping # jetty.httpConfig.maxErrorDispatches=10 ## Maximum time to block in total for a blocking IO operation (default -1 is to use idleTimeout on progress) # jetty.httpConfig.blockingTimeout=-1 ## Cookie compliance mode of: RFC2965, RFC6265 # jetty.httpConfig.cookieCompliance=RFC6265 ### Server configuration ## Whether ctrl+c on the console gracefully stops the Jetty server # jetty.server.stopAtShutdown=true ## Timeout in ms to apply when stopping the server gracefully # jetty.server.stopTimeout=5000 ## Dump the state of the Jetty server, components, and webapps after startup # jetty.server.dumpAfterStart=false ## Dump the state of the Jetty server, components, and webapps before shutdown # jetty.server.dumpBeforeStop=false ## The name to uniquely identify this server instance #jetty.defaultSessionIdManager.workerName=node1 ## How frequently sessions are inspected #jetty.sessionInspectionInterval.seconds=60 # --------------------------------------- # Module: jsp # Enables JSP for all webapplications deployed on the server. # --------------------------------------- --module=jsp # --------------------------------------- # Module: resources # Adds the $JETTY_HOME/resources and/or $JETTY_BASE/resources # directory to the server classpath. Useful for configuration # property files (eg jetty-logging.properties) # --------------------------------------- --module=resources # --------------------------------------- # Module: deploy # Enables webapplication deployment from the webapps directory. # --------------------------------------- --module=deploy # Monitored directory name (relative to $jetty.base) # jetty.deploy.monitoredDir=webapps # - OR - # Monitored directory path (fully qualified) # jetty.deploy.monitoredPath=/var/www/webapps # Defaults Descriptor for all deployed webapps # jetty.deploy.defaultsDescriptorPath=${jetty.base}/etc/webdefault.xml # Monitored directory scan period (seconds) # jetty.deploy.scanInterval=1 # Whether to extract *.war files # jetty.deploy.extractWars=true # --------------------------------------- # Module: jstl # Enables JSTL for all webapplications deployed on the server # --------------------------------------- --module=jstl # --------------------------------------- # Module: websocket # Enable websockets for deployed web applications # --------------------------------------- --module=websocket # --------------------------------------- # Module: http # Enables a HTTP connector on the server. # By default HTTP/1 is support, but HTTP2C can # be added to the connector with the http2c module. # --------------------------------------- --module=http ### HTTP Connector Configuration ## Connector host/address to bind to # jetty.http.host=0.0.0.0 ## Connector port to listen on # jetty.http.port=8080 jetty.http.port=8090 ## Connector idle timeout in milliseconds # jetty.http.idleTimeout=30000 ## Connector socket linger time in seconds (-1 to disable) # jetty.http.soLingerTime=-1 ## Number of acceptors (-1 picks default based on number of cores) # jetty.http.acceptors=-1 ## Number of selectors (-1 picks default based on number of cores) # jetty.http.selectors=-1 ## ServerSocketChannel backlog (0 picks platform default) # jetty.http.acceptorQueueSize=0 ## Thread priority delta to give to acceptor threads # jetty.http.acceptorPriorityDelta=0 ## HTTP Compliance: RFC7230, RFC2616, LEGACY # jetty.http.compliance=RFC7230
基本設定
一般設定
jetty.home
Jettyがインストールされているディレクトリ。
この値は固定であり、設定しても変更されない。
jetty.base
WEBアプリケーションをデプロイするディレクトリ。
設定ファイルはここで指定したディレクトリから読み込まれる。
パラメータ”jetty.home”と同じでもよいが、公式には別のパスにすることが推奨されている。
別のパスにすることによって、jetty.homeディレクトリは一切変更する必要がなくなるので、バージョンアップの際、移行が容易になるからである。
ただ、プロパティファイル”start.ini”とwebappsディレクトリ程度しか使用しないのであれば、jetty.homeディレクトリと同じでもよいだろう。
- デフォルト
jetty.base=<実行時パス>
user.dir
ログ出力など、Jettyに組み込まれたサードパーティのライブラリで使用されるパスである。
一定の場所に設定すべきである。
serverモジュール
サーバとして動作させるための基本的な設定を行う。
- モジュール設定
--module=server
スレッドプール
minThreads
# Minimum number of threads
- デフォルト
jetty.threadPool.minThreads=10
maxThreads
# Maximum number of threads
- デフォルト
jetty.threadPool.maxThreads=200
idleTimeout
# Thread idle timeout (in milliseconds)
- デフォルト
jetty.threadPool.idleTimeout=60000
HTTP全般
# Scheme to use to build URIs for secure redirects
- デフォルト
jetty.httpConfig.secureScheme=https
# Port to use to build URIs for secure redirects
- デフォルト
jetty.httpConfig.securePort=8443
# Response content buffer size (in bytes)
- デフォルト
jetty.httpConfig.outputBufferSize=32768
# Max response content write length that is buffered (in bytes)
- デフォルト
jetty.httpConfig.outputAggregationSize=8192
# Max request headers size (in bytes)
- デフォルト
jetty.httpConfig.requestHeaderSize=8192
# Max response headers size (in bytes)
- デフォルト
jetty.httpConfig.responseHeaderSize=8192
# Whether to send the Server: header
- デフォルト
jetty.httpConfig.sendServerVersion=true
# Whether to send the Date: header
- デフォルト
jetty.httpConfig.sendDateHeader=false
# Max per-connection header cache size (in nodes)
- デフォルト
jetty.httpConfig.headerCacheSize=512
# Whether, for requests with content, delay dispatch until some content has arrived
- デフォルト
jetty.httpConfig.delayDispatchUntilContent=true
# Maximum number of error dispatches to prevent looping
- デフォルト
jetty.httpConfig.maxErrorDispatches=10
# Maximum time to block in total for a blocking IO operation (default -1 is to use idleTimeout on progress)
- デフォルト
jetty.httpConfig.blockingTimeout=-1
# Cookie compliance mode of: RFC2965, RFC6265
- デフォルト
jetty.httpConfig.cookieCompliance=RFC6265
## Server configuration
# Whether ctrl+c on the console gracefully stops the Jetty server
- デフォルト
jetty.server.stopAtShutdown=true
# Timeout in ms to apply when stopping the server gracefully
- デフォルト
jetty.server.stopTimeout=5000
# Dump the state of the Jetty server, components, and webapps after startup
- デフォルト
jetty.server.dumpAfterStart=false
# Dump the state of the Jetty server, components, and webapps before shutdown
- デフォルト
jetty.server.dumpBeforeStop=false
# The name to uniquely identify this server instance
- デフォルト
jetty.defaultSessionIdManager.workerName=node1
# How frequently sessions are inspected
- デフォルト
jetty.sessionInspectionInterval.seconds=60
ログ
ログ関連はモジュール有効化以外は下記パスのファイルで設定する。
vi $JETTY_HOME/resources/jetty-logging.properties
console-captureモジュール
標準(エラー)出力に出力されるログをファイルに出力する設定を行う。
- モジュール設定
--module=console-capture
dir
ログの出力ディレクトリ。
相対パスを記述すると$jetty.baseからの相対パスとなる。
プロパティ”filePath”でこのプロパティを指定しないと、このディレクトリに出力されない。
- デフォルト
jetty.console-capture.dir=logs
append
既存のファイルがある場合、追記するかどうか。
- デフォルト
jetty.console-capture.append=true
retainDays
過去のログを何日残すかどうか。
- デフォルト
jetty.console-capture.retainDays=90
timezone
ログに記載される時刻のタイムゾーン
- 設定値
日本の場合は通常以下から選ぶ。
jetty.console-capture.timezone=[ GMT | JST ]
- デフォルト
jetty.console-capture.timezone=GMT
requestlogモジュール
アクセスログ関係の設定を行う。
ログファイルは日次で自動でローテーションされるが、ログファイル名に日付を含めなければならない。
- モジュール設定
--module=requestlog
dir
ログの出力ディレクトリ。
相対パスを記述すると$jetty.baseからの相対パスとなる。
プロパティ”filePath”でこのプロパティを指定しないと、このディレクトリに出力されない。
- デフォルト
jetty.requestlog.dir=logs
filePath
ログの出力パス。
パス中の文字列”yyyy_mm_dd”の部分はプロパティ”filenameDateFormat”で置き換えられる。
プロパティ”filenameDateFormat”でどのような書式であろうと、このプロパティ中の日付部分は必ず”yyyy_mm_dd”である必要がある。
- デフォルト
jetty.requestlog.filePath=${jetty.requestlog.dir}/yyyy_mm_dd.request.log
filenameDateFormat
ログファイルのファイル名中で用いられる日付部分の書式。
SimpleDateFormatクラスで指定できる書式である必要がある。
- デフォルト
jetty.requestlog.filenameDateFormat=yyyy_MM_dd
retainDays
過去のログを何日残すかどうか。
- デフォルト
jetty.requestlog.retainDays=90
append
既存のファイルがある場合、追記するかどうか。
- デフォルト
jetty.requestlog.append=false
extended
詳細なログ情報を出力するかどうか。
- デフォルト
jetty.requestlog.extended=true
クッキーの内容を記録するかどうか。
- デフォルト
jetty.requestlog.cookies=true
timezone
ログに記載される時刻のタイムゾーン
- 設定値
日本の場合は通常以下から選ぶ。
jetty.requestlog.timezone=[ GMT | JST ]
- デフォルト
jetty.requestlog.timezone=GMT
loglatency
応答時間を記録するかどうか。
ミリ秒で記録される。
- デフォルト
jetty.requestlog.loglatency=false
logging-jettyモジュール
アプリケーションログの設定を行う。
- モジュール設定
--module=logging-jetty
log.class
ログ出力クラスを指定する。
- 設定値
org.eclipse.jetty.util.log.class=<ログ出力クラス>
- デフォルト
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
log.class
ログ出力クラスを指定する。
- 設定値
org.eclipse.jetty.util.log.class=<ログ出力クラス>
- デフォルト
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
LEVEL
ログ出力レベルを指定する。
ALLの場合は、DEBUGが除かれるので注意。
- 設定値
<対象パッケージ>.LEVEL={ ALL | DEBUG | INFO | WARN | OFF }
- デフォルト
com.example.LEVEL=INFO
- Jetty自体のログレベルも設定できる。
org.eclipse.jetty.LEVEL=INFO
STACKS
スタックトレースを出力するかどうかを指定する。
- 設定値
<対象パッケージ>.STACKS={ true | false }
- デフォルト
com.example.STACKS=false
SOURCE
ソースコードの位置を出力するかどうかを指定する。
- 設定値
<対象パッケージ>.SOURCE={ true | false }
- デフォルト
com.example.SOURCE=false
セキュリティ
sslモジュール (httpsモジュール)
SSL/TLS関係の設定を行う。
HTTPSモジュールを読み込むとこのモジュールも自動で読み込まれる。
- モジュール設定
通常はhttpsモジュールを読み込むことで、併せてsslモジュールを読み込む
--module=https
sslモジュールのみを読み込む場合
--module=ssl
ネットワーク
host
SSL/TLS接続を許可するインタフェース(IPアドレス)を指定する
- デフォルト
jetty.ssl.host=0.0.0.0
port
SSL/TLS接続を待ち受けるポート番号を指定する
- デフォルト
jetty.ssl.port=8443
idleTimeout
アイドル状態になった接続のタイムアウト時間
- 設定値
jetty.ssl.idleTimeout=<時間(ミリ秒)>
- デフォルト
jetty.ssl.idleTimeout=30000
soLingerTime
Lingerタイムアウトまでの時間を設定する。
Lingerタイムアウトとはソケットにclose命令が出されても、直ちに閉じずに、未送信データの送信とその受信応答受け取りが完了するまでソケットのクローズを待機する時間である。
- 設定値
jetty.ssl.soLingerTime={ <時間(秒)> | -1 }
値を-1にした場合、無効となる。
- デフォルト
jetty.ssl.soLingerTime=-1
証明書・秘密鍵データベース
keyStorePath
秘密鍵データベースのパスを指定する。
相対パスを指定する場合、$jetty.baseが基点となる。
- デフォルト
jetty.sslContext.keyStorePath=etc/keystore
trustStorePath
証明書データベースのパスを指定する。
相対パスを指定する場合、$jetty.baseが基点となる。
- デフォルト
jetty.sslContext.trustStorePath=etc/keystore
keyStoreType
使用する鍵データベースの種類
- 設定値
jetty.sslContext.keyStoreType={ JKS | PKCS12 }
- デフォルト
jetty.sslContext.keyStoreType=JKS
trustStoreType
使用する証明書データベースの種類
- 設定値
jetty.sslContext.trustStoreType={ JKS | PKCS12 }
- デフォルト
jetty.sslContext.trustStoreType=JKS
keyStoreProvider
使用する鍵データベースの提供元
- 設定値
jetty.sslContext.keyStoreProvider=[<データベース提供元>]
設定しない場合、Java標準のものが使用される。
- デフォルト
jetty.sslContext.keyStoreProvider=
trustStoreProvider
使用する証明書データベースの提供元
- デフォルト
jetty.sslContext.trustStoreProvider=
keyStorePassword
秘密鍵データベースのパスワードを指定する。
パスワードはOBF、MD5、CRYPT形式が扱え、それぞれを生成するには次のコマンドを実行する。
java -cp $JETTY_HOME/lib/jetty-util-*.jar org.eclipse.jetty.util.security.Password <パスワード>
- デフォルト
jetty.sslContext.keyStorePassword=OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4
復号すると”storepwd”となる。
trustStorePassword
証明書データベースのパスワードを指定する。
パスワードはOBF、MD5、CRYPT形式が扱え、それぞれを生成するには次のコマンドを実行する。
java -cp $JETTY_HOME/lib/jetty-util-*.jar org.eclipse.jetty.util.security.Password <パスワード>
- デフォルト
jetty.sslContext.trustStorePassword=OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4
復号すると”storepwd”となる。
keyManagerPassword
鍵マネージャーのパスワードを指定する。
パスワードはOBF、MD5、CRYPT形式が扱え、それぞれを生成するには次のコマンドを実行する。
java -cp $JETTY_HOME/lib/jetty-util-*.jar org.eclipse.jetty.util.security.Password <パスワード>
- デフォルト
jetty.sslContext.keyManagerPassword=OBF:1u2u1wml1z7s1z7a1wnl1u2g
復号すると”keypwd”となる。
acceptor / selector
acceptorとは新たな接続を受け付け、ソケットを生成するスレッドのことである。
selectorとは生成されたソケットを管理するスレッドのことである。
acceptors
acceptorスレッドの数
- 設定値
jetty.ssl.acceptors=<スレッド数>
値を-1にした場合、CPUコア数に基づいて自動で算定される。
- デフォルト
jetty.ssl.acceptors=-1
acceptorQueueSize
ServerSocketChannel backlog (0 picks platform default)
- デフォルト
jetty.ssl.acceptorQueueSize=0
acceptorPriorityDelta
Thread priority delta to give to acceptor threads
- デフォルト
jetty.ssl.acceptorPriorityDelta=0
selectors
selectorスレッドの数
- 設定値
jetty.ssl.selectors=<スレッド数>
値を-1にした場合、CPUコア数に基づいて自動で算定される。
- デフォルト
jetty.ssl.selectors=-1
Strict-Transport-Security(SSL/TLS使用の要求)
stsMaxAgeSeconds
max age in seconds for a Strict-Transport-Security response header (default -1)
- デフォルト
jetty.ssl.stsMaxAgeSeconds=31536000
stsIncludeSubdomains
include subdomain property in any Strict-Transport-Security header (default false)
- デフォルト
jetty.ssl.stsIncludeSubdomains=true
クライアント証明書
needClientAuth
クライアント証明書を必須とするかどうか
- デフォルト
jetty.sslContext.needClientAuth=false
wantClientAuth
クライアント証明書を要求するかどうか。
ただし、クライアントが証明書を送信しなかったとしても接続を拒否しない。
- デフォルト
jetty.sslContext.wantClientAuth=false
キャッシュ
sslSessionCacheSize
SSLセッションのキャッシュサイズ
- デフォルト
jetty.sslContext.sslSessionCacheSize=-1
sslSessionTimeout
SSLセッションのキャッシュのタイムアウト時間
- 設定値
jetty.sslContext.sslSessionTimeout={ <時間(秒)> | -1 }
値を-1にした場合、タイムアウトしない。
- デフォルト
jetty.sslContext.sslSessionTimeout=-1
再ネゴシエーション
renegotiationAllowed
利用中のSSL通信で使用している暗号化パラメータについて再設定要求がクライアントからあった場合、受け付けるかどうか。
- デフォルト
jetty.sslContext.renegotiationAllowed=true
renegotiationLimit
利用中のSSL通信で使用している暗号化パラメータについて再設定要求がクライアントからあった場合、最大何回まで受け付けるか。
- デフォルト
jetty.sslContext.renegotiationLimit=5
その他
sniHostCheck
Server Name Indication(SNI)とはSSL/TLS使用時にクライアントがアクセスしたいドメイン名を指定することで、同一のサーバが複数のドメイン名用の証明書を使い分けることができる、SSLの拡張機能である。
クライアントから要求されたホスト名が実際にサーバが保持するSNIと一致するかどうかチェックしてから証明書を返すかどうか。
- デフォルト
jetty.ssl.sniHostCheck=true
useCipherSuitesOrder
暗号アルゴリズムを設定された順序で選択して使用するかどうか。
このオプションはJava8以降で使用可能である。
特定の暗号アルゴリズムを使用する、または使用しないように設定することもできる。
- デフォルト
jetty.sslContext.useCipherSuitesOrder=true
リライト
rewriteRequestURI
URLの書き換えを有効にするかどうか
- 設定値
jetty.rewrite.rewriteRequestURI=[ true | false ]
rewritePathInfo
パスの書き換えを有効にするかどうか
- 設定値
jetty.rewrite.rewritePathInfo=[ true | false ]
originalPathAttribute
書き換えた後に書き換え前のパスをURLのクエリとして渡すようにする。
そのクエリの属性名(キー)を指定する。
- 設定値
jetty.rewrite.originalPathAttribute=<属性名>
プロキシ・バランサ
フォワード・リバースプロキシサーバとして動作させることができる。
実態はサーブレットであり、サーバで特定のパスに対し、プロキシ用のサーブレットが内部でHTTPクライアントとして処理を行い、結果を返す。
- 参考:http://www.eclipse.org/jetty/documentation/current/proxy-servlet.html
ただし、現バージョンではプロキシ用のサーブレットは問題があり、リバースプロキシとして正常に動作しない。
サーブレット内部でコンテキストパスを取得して転送先URLを生成するのだが、単体のWebアプリケーションとして登録しないためコンテキストパスがnullになり、URLを生成できない。
サーブレットの登録方法を変えるなどの情報がWebにあるが、試したところ、いずれもうまくいかなかった。
その為、リバースプロキシにはバランサ用のサーブレットを使用するとよい。
ただ、試したところ、リバースプロキシとしては動作したが、その他のWebアプリケーション、静的ファイルの応答がなされなくなった。使用する場合は、リバースプロキシ専用として使用する必要がある。
バランサは複数のホストにリクエストを転送できる機能である。
X-Forwarded-ForなどのHTTPヘッダは特に設定しなくても自動で生成される。
プロキシ・バランサモジュール
プロキシ、またはバランサの機能を使用する際に設定する。
- モジュール設定
--module=proxy
- ログ設定
org.eclipse.jetty.proxy.LEVEL=<ログレベル>
共用設定
servletClass
プロキシ機能を実現するサーブレットのクラスを指定する。
デフォルトのProxyServletの場合、フォワードプロキシとして動作する。
リバースプロキシの場合は、設定変更する必要がある。
- 設定値
jetty.proxy.servletClass=<クラス名>
- フォワードプロキシ
jetty.proxy.servletClass=org.eclipse.jetty.proxy.ProxyServlet
- リバースプロキシ
jetty.proxy.servletClass=org.eclipse.jetty.proxy.ProxyServlet$Transparent
- バランサ
jetty.proxy.servletClass=org.eclipse.jetty.proxy.BalancerServlet
- フォワードプロキシ
- デフォルト
jetty.proxy.servletClass=org.eclipse.jetty.proxy.ProxyServlet
maxThreads
- 設定値
jetty.proxy.maxThreads=<スレッド数>
- デフォルト
jetty.proxy.maxThreads=128
maxConnections
- 設定値
jetty.proxy.maxConnections=<コネクション数>
- デフォルト
jetty.proxy.maxConnections=256
idleTimeout
- 設定値
jetty.proxy.idleTimeout=<タイムアウト時間>
- デフォルト
jetty.proxy.idleTimeout=30000
timeout
- 設定値
jetty.proxy.timeout=<タイムアウト時間>
- デフォルト
jetty.proxy.timeout=60000
hostHeader
forces the host header to a particular value
XMLファイルに設定追加が必要
viaHost
the name to use in the Via header: Via: http/1.1 <viaHost>
XMLファイルに設定追加が必要
whiteList
comma-separated list of allowed proxy hosts
XMLファイルに設定追加が必要
blackList
comma-separated list of forbidden proxy hosts
XMLファイルに設定追加が必要
プロキシ用設定
servletMapping
プロキシ対象とするパスを指定する。
つまり、プロキシサーブレットが動作するパスである。
- 設定値
jetty.proxy.servletMapping=<パス>
- デフォルト
jetty.proxy.servletMapping=/*
proxyTo
リバースプロキシ(org.eclipse.jetty.proxy.ProxyServlet$Transparent)として使用するときのみ指定可能。
ただし、対応するXMLファイルには本パラメータは記載がないので、追記が必要。
vi $JETTY_HOME/etc/jetty-proxy.xml追記内容は下記。
<Call name="setInitParameter"> <Arg>proxyTo</Arg> <Arg><Property name="jetty.proxy.proxyTo"/></Arg> </Call>
- 設定値
jetty.proxy.proxyTo=<URL>
例えば、URLを「http://example.com/test/」とした場合、プロキシサーバのURLが「http://proxy.example.com/proxy/」であれば、「http://proxy.example.com/proxy/hello」のリクエストに対し、プロキシは「http://example.com/test/hello」にリクエストを行う。
- デフォルト
なし
バランサ用設定
stickySessions
同じ接続元からのアクセスを前回と同じサーバに転送するかどうか。
- 設定値
jetty.proxy.stickySessions=[ true | false ]
- true
同じサーバに転送する - false
同じサーバに転送されるとは限らない
- true
- デフォルト
jetty.proxy.stickySessions=false
- 設定ファイル(.xml)の変更が必要
- 対象設定ファイル
vi $JETTY_HOME/etc/jetty-proxy.xml
- 設定内容
<Call name="setInitParameter"> <Arg>stickySessions</Arg> <Arg><Property name="jetty.proxy.stickySessions" default="false" /></Arg> </Call>
- 対象設定ファイル
balancerMember.<name>.proxyTo
リクエストの転送先と、パスの書き換え設定を行う。
name部分には転送先のホスト名を記載する。
ただし、設定ファイル(.xml)はワイルドカードを使用した設定ができないので、プロパティファイル(.ini)に記載しても、変更時にプロパティファイルだけでなく、設定ファイル(.xml)の修正が必要になる。
その為、プロパティファイルには記載せずに、設定ファイルにのみ記載した方がよい。
- 設定ファイル(.xml)の変更が必要
- 対象設定ファイル
vi $JETTY_HOME/etc/jetty-proxy.xml
- 設定内容
URLの末尾には自動で/が付けられるので、/を記載してはならない。
バランササーブレットを有効にしたパス部分は除去されないので注意すること。(下記設定例を参照)
<Call name="setInitParameter"> <Arg>balancerMember.<name>.proxyTo</Arg> <Arg>転送先のURL</Arg> </Call>
- 設定例1
<Call name="setInitParameter"> <Arg>balancerMember.192.168.0.1.proxyTo</Arg> <Arg>http://192.168.0.1</Arg> </Call>
この場合、http(s)://example.com/test1/test2/test3へのアクセスはhttp://192.168.0.1/test1/test2/test3へと転送される。 - 設定例2
<Call name="setInitParameter"> <Arg>balancerMember.192.168.0.1:8080.proxyTo</Arg> <Arg>http://192.168.0.1:8080/test1</Arg> </Call>
この場合、http(s)://example.com/test1/test2/test3へのアクセスはhttp://192.168.0.1:8080/test1/test1/test2/test3へと転送される。
- 対象設定ファイル
モジュールファイル(.mod)
モジュールファイルにはプロパティ一覧が記載されている。
- プロパティ一覧抽出(説明なし)
cat $JETTY_HOME/modules/XXX.mod | egrep "^#[^#]" | sed "s/^# \?//g"
- プロパティ一覧抽出(説明あり)
cat $JETTY_HOME/modules/XXX.mod | egrep "^#" | sed "s/^# \?//g"
モジュール一覧
find modules -name "*.mod" | sed -e "s/.*\///g" -e "s/.mod//" | sort
- 実行結果
acceptratelimit address alpn alpn-10 alpn-11 alpn-12 alpn-1.8.0 alpn-1.8.0_05 alpn-1.8.0_101 alpn-1.8.0_102 alpn-1.8.0_11 alpn-1.8.0_111 alpn-1.8.0_112 alpn-1.8.0_121 alpn-1.8.0_131 alpn-1.8.0_141 alpn-1.8.0_144 alpn-1.8.0_151 alpn-1.8.0_152 alpn-1.8.0_161 alpn-1.8.0_162 alpn-1.8.0_171 alpn-1.8.0_172 alpn-1.8.0_181 alpn-1.8.0_20 alpn-1.8.0_25 alpn-1.8.0_31 alpn-1.8.0_40 alpn-1.8.0_45 alpn-1.8.0_51 alpn-1.8.0_60 alpn-1.8.0_65 alpn-1.8.0_66 alpn-1.8.0_71 alpn-1.8.0_72 alpn-1.8.0_73 alpn-1.8.0_74 alpn-1.8.0_77 alpn-1.8.0_91 alpn-1.8.0_92 alpn-8 alpn-9 alpn-impl annotations apache-jsp apache-jstl cdi cdi1 cdi2 client connectionlimit conscrypt console-capture continuation datasource debug debuglog deploy driver ext fcgi flight-recorder gcloud gcloud-datastore global-webapp-common gzip hawtio hazelcast-embedded-sessions hazelcast-remote-sessions home-base-warning http http2 http2c http-forwarded https ipaccess jaas jamon jaspi jcl-slf4j jminix jmx jmx-remote jndi jolokia jsp jstl jul-impl jul-slf4j jvm log4j2-api log4j2-impl log4j2-slf4j log4j-impl logback-access logback-impl logging-jetty logging-jul logging-log4j logging-log4j2 logging-logback logging-slf4j lowresources mail plus proxy proxy-protocol proxy-protocol-ssl quickstart requestlog resources rewrite rewrite-compactpath rewrite-customizer security server servlet servlets session-cache-hash session-cache-null sessions session-store-cache session-store-file session-store-gcloud session-store-hazelcast-embedded session-store-hazelcast-remote session-store-infinispan-embedded session-store-infinispan-embedded-910 session-store-infinispan-remote session-store-infinispan-remote-910 session-store-jdbc session-store-mongo setuid slf4j-api slf4j-jul slf4j-log4j slf4j-log4j2 slf4j-logback slf4j-simple-impl spring ssl stats stop threadlimit threadpool transactions unixsocket unixsocket-forwarded unixsocket-http unixsocket-http2c unixsocket-proxy-protocol unixsocket-secure uri webapp websocket xmemcached
基本機能
server
サーバ機能を使用するモジュール。
- パス
modules/server.mod
リライト
rewrite
リクエストされたURLの書き換えを行う
rewrite-compactpath
スラッシュが複数連続して並んだのURLをスラッシュ一つに書き換える
例えば http://example.com/aaa///index.html を http://example.com/aaa/index.html のように修正する。
- 依存モジュール
- rewrite
rewrite-customizer
URL以外のHTTPリクエスト内容を書き換える
設定ファイル(.xml)
設定ファイルはetcディレクトリ内に格納されているが、参照元のモジュールファイルを変更すれば、etcディレクトリ以外でも保存可能である。
プロキシ
プロキシサーバとしての機能を有効にするモジュール
proxy
プロキシ設定を行う
proxy-protocol
非暗号化通信でのプロキシを有効化する
proxy-protocol-ssl
暗号化通信でのプロキシを有効化する
http-forwarded
Jettyがプロキシ経由でアクセスされた際にJettyがプロキシサーバを透過的に扱うモジュール
jetty.xml
jettyサーバに対して設定を行う。
- 参照元
server.mod
webdefault.xml
全てのウェブアプリケーションの設定ファイル”web.xml”に対してデフォルトの設定を与える。
- 参照元
deploy.mod
※jetty-deploy.xmlより間接参照
Tips
認証設定
Digest認証
一括認証設定
全てのWEBアプリケーションに対してDigest認証を行うよう設定する。
1つのWEBアプリケーションにログインすると別のWEBアプリケーションに対しては改めてのログインは不要となる。
$JETTY_HOME/webapps/ROOT配下の静的ファイルに対しても認証がかかってしまうので注意。
これを回避するには、WEBアプリケーション個別に設定をしなければならない。
- 手順
- users
ユーザ情報を格納するテキストファイルを新規に作成する。
次の条件で作成した。
- ファイル:$JETTY_HOME/users
- ユーザ名:admin
- パスワード:password
- ロール名:admin1とadmin2
- users
echo "admin: password,admin1,admin2" > users chown jetty:jetty users
パスワードを暗号化する場合は以下
echo "admin: `java -cp $JETTY_HOME/lib/jetty-util-9.4.6.v20170531.jar org.eclipse.jetty.util.security.Password password 2>&1 | grep MD5`,admin1,admin2" > users
- etc/webdefault.xml
rootエレメント”web-app”内に以下を追加する。
url-patternの設定を変更することで、特定のパスやファイル拡張子に対してのみ認証をかけることもできる。
特定パスを記述する場合、コンテキストルート下からのパスを記述する必要がある。
hello.warファイルをデプロイする場合、/hello/testのパスに認証をかける場合、/testと書く。
これは他のwarファイルやROOT配下に同じパスでアクセス可能な場合も認証が求めれることになる。
<security-constraint> <web-resource-collection> <url-pattern>/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>admin</role-name> </auth-constraint> </security-constraint> <login-config> <auth-method>DIGEST</auth-method> </login-config>
- etc/jetty.xml
rootエレメント”Configure”内に以下を追加する。
<Call name="addBean"> <Arg> <New class="org.eclipse.jetty.security.HashLoginService"> <Set name="config">users</Set> <Set name="hotReload">false</Set> </New> </Arg> </Call>
- 既存のjetty.xmlを変更しないパターン
etc/jetty.xmlを変更せずに別途xmlファイルを作成することもできる。
任意の場所にxmlファイルを作成する。
今回は$JETTY_HOME直下とした。
cat > $JETTY_HOME/my.xml << EOT <?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd"> <Configure id="Server" class="org.eclipse.jetty.server.Server"> <Call name="addBean"> <Arg> <New class="org.eclipse.jetty.security.HashLoginService"> <Set name="config">users</Set> <Set name="hotReload">false</Set> </New> </Arg> </Call> </Configure> EOT
プロパティファイルにxmlのパスを指定する
echo my.xml >> $JETTY_HOME/start.ini
個別認証設定
特定のWEBアプリケーションに対してのみ認証をかける場合は以下の設定を行う。
個別のWEBアプリケーションに設定を行うことで、細かなパスのみに認証をかけるということがやりやすい。
以下ではWEBアプリケーションtest.warファイルをデプロイするという前提である。
- 手順
- users
ユーザ情報を格納するテキストファイルを新規に作成する。
次の条件で作成した。
- ファイル:$JETTY_HOME/users
- ユーザ名:admin
- パスワード:password
- ロール名:admin1とadmin2
- users
echo "admin: password,admin1,admin2" > users chown jetty:jetty users
パスワードを暗号化する場合は以下
echo "admin: `java -cp $JETTY_HOME/lib/jetty-util-9.4.6.v20170531.jar org.eclipse.jetty.util.security.Password password 2>&1 | grep MD5`,admin1,admin2" > users
- 専用web.xmlファイル
このファイルの名前は他の設定中で直接指定するので何でも良いのだが、”<warファイル名>-web.xml”としておくとわかりやすい。
ただし、配置パスはwebappsディレクトリ直下ではいけない。
Jettyホームディレクトリ直下か直下に設定ファイル用のディレクトリを作成しそこに置く、またははwebappsディレクトリ直下にWEBアプリケーション専用の設定ファイルディレクトリを作成し、そこに置くかである。
- $JETTY_HOME/test-web.xml
- $JETTY_HOME/webconf/test-web.xml
※webconfは例 - $JETTY_HOME/webapps/test.d/test-web.xml
webapps配下に置く場合、自動デプロイ機能の関係で必ず上記のようなパスにしなければならない。
そうでないと、以下のような例外が発生する。
java.lang.IllegalStateException: Unknown configuration type: web-app in org.eclipse.jetty.deploy.providers.WebAppProvider$1@271053e1
今回は1つ目のJettyホームディレクトリ直下に置くことにする。
cat > $JETTY_HOME/test-web.xml << EOT <?xml version="1.0" encoding="UTF-8"?> <web-app \txmlns="http://xmlns.jcp.org/xml/ns/javaee" \txmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \txsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" \tmetadata-complete="false" \tversion="3.1"> \t \t<security-constraint> \t\t<web-resource-collection> \t\t\t<url-pattern>/*</url-pattern> \t\t</web-resource-collection> \t\t \t\t<auth-constraint> \t\t\t<role-name>admin</role-name> \t\t</auth-constraint> \t\t<login-config> \t\t\t<auth-method>DIGEST</auth-method> \t\t</login-config> \t</security-constraint> </web-app> EOT sed -i -e "s/\\\\t/\t/g" $JETTY_HOME/test-web.xml chmod 640 $JETTY_HOME/test-web.xml chown jetty:jetty $JETTY_HOME/test-web.xml
- 専用jetty.xmlファイル
webappsディレクトリにデプロイしたwarファイルと同名のxmlファイルを設置すると、そのファイルは当該WEBアプリケーション専用のjetty.xmlファイルとなる。
cat > $JETTY_HOME/webapps/test.xml << EOT <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd"> <Configure id="testWebapp" class="org.eclipse.jetty.webapp.WebAppContext"> \t<Set name="contextPath">/test</Set> \t<Set name="war"><Property name="jetty.webapps" default="."/>/test.war</Set> \t \t<Set name="extractWAR">true</Set> \t<Set name="copyWebDir">false</Set> \t \t<Set name="overrideDescriptor"><Property name="jetty.home" default="."/>/test-web.xml</Set> \t \t<Get name="securityHandler"> \t\t<Set name="loginService"> \t\t\t<New class="org.eclipse.jetty.security.HashLoginService"> \t\t\t\t<Set name="config"><SystemProperty name="jetty.home" default="."/>/users</Set> \t\t\t</New> \t\t</Set> \t</Get> </Configure> EOT sed -i -e "s/\\\\t/\t/g" $JETTY_HOME/webapps/test.xml chmod 640 $JETTY_HOME/webapps/test.xml chown jetty:jetty $JETTY_HOME/webapps/test.xml
SSL/TLS
予めSSL/TLS証明書と秘密鍵を用意しておく必要がある。
この時、自己生成した公開鍵・秘密鍵ペアを使用する場合と使用しない場合で手順が異なる。
- 自己生成した公開鍵・秘密鍵ペアを使用しない場合
- keystoreを生成する
Jetty等のJavaベースのサーブレットコンテナでは通常の証明書・秘密鍵の形式では読み込めない。
その為、keystoreというファイルを生成し、そこに証明書等を格納する必要がある。
- パスワードの設定
keystoreを生成するにはパスワードが必要である。
プロンプトに手動で入力しても良いが、簡単のためファイルに書き込んでおく。
echo <パスワード> > keystore-password chmod 400 keystore-password
- pkcs12形式に変換する
自己生成でない、既存の証明書・秘密鍵を用いる場合、PKCS12という形式でないと、keystoreに格納することができない。
その為、PKCS12形式に変換する。
openssl pkcs12 -inkey <秘密鍵> -in <証明書> -export -out key-csr.pkcs12 -passout file:keystore-password
- パスワードの設定
- keystoreを生成、証明書等を格納する
keytool -importkeystore -srckeystore key-csr.pkcs12 -srcstoretype PKCS12 -srcstorepass `cat keystore-password` -destkeystore keystore -deststorepass `cat keystore-password`
- Jettyにインストールする
mv keystore $JETTY_HOME/etc/
- JettyにSSLを設定する
- パスワードを暗号化する
Jettyがkeystoreを読み取るために設定したパスワードが必要である。
しかし、設定ファイルに直接パスワードを記載するので、平文ではなく暗号化しておく。
暗号化はいくつかの方式があるが、今回はOBFを使用する。
JETTY_KEYSTORE_PASSWORD=`java -cp $JETTY_HOME/lib/jetty-util-*.jar org.eclipse.jetty.util.security.Password \`cat keystore-password\` 2>&1 | grep OBF`
- 設定を行う
cat >> $JETTY_HOME/start.ini << EOT --module=https jetty.ssl.port=443 jetty.sslContext.keyStoreType=PKCS12 jetty.sslContext.trustStoreType=PKCS12 jetty.sslContext.keyStorePassword=$JETTY_KEYSTORE_PASSWORD jetty.sslContext.keyManagerPassword=$JETTY_KEYSTORE_PASSWORD EOT unset JETTY_KEYSTORE_PASSWORD
- 設定を反映する
jetty.sh restart
- パスワードを暗号化する
- 不要であるならパスワードファイルは削除しておく
rm -f keystore-password
- keystoreを生成する
リバースプロキシ
/proxy/へのアクセスを10.0.0.1:8080に転送する。
リバースプロキシはバランササーブレットを使用して行う。
- xmlファイルを変更する
vi $JETTY_HOME/etc/jetty-proxy.xml
他の「<Call name=”setInitParameter”>」の末尾に下記を追記する。
<Call name="setInitParameter"> <Arg>balancerMember.10.0.0.1:8080.proxyTo</Arg> <Arg>http://10.0.0.1:8080</Arg> </Call> <Call name="setInitParameter"> <Arg>stickySessions</Arg> <Arg><Property name="jetty.proxy.stickySessions" default="false" /></Arg> </Call>
- start.iniを修正する
cat >> $JETTY_HOME/start.ini << EOT --module=proxy jetty.proxy.servletClass=org.eclipse.jetty.proxy.BalancerServlet jetty.proxy.servletMapping=/proxy/* EOT
- 設定を反映する
systemctl restart jetty
or
jetty.sh restart