在Jetty 8中,覆盖标准服务器端口并在自定义jetty.xml
文件中添加SSL连接器相当容易,如下所示:
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<Set name="port">8984</Set>
<Set name="confidentialPort">8986</Set>
</New>
</Arg>
</Call>
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.ssl.SslSelectChannelConnector">
<Set name="Port">8986</Set>
<!-- keystore, password, keyPassword, ... -->
</New>
</Arg>
</Call>
</Configure>
由于Jetty 9不再接受此配置,因此我检查了Jetty documentation及相关的StackOverflow问题(如How to override jetty.xml with jetty.port),但没有成功。
如何重写配置以在Jetty 9中执行相同的操作?
答案 0 :(得分:1)
使用Jetty 9几乎没有理由再编辑XML文件。
使用Jetty 9模块系统和${jetty.base}
概念。
$ cd /opt/jetty
$ tar -zxvf jetty-distribution-9.3.3.v20150827.tar.gz
$ mkdir my.base
$ cd my.base
$ java -jar ../jetty-distribution-9.3.3.v20150827/start.jar \
--add-to-start=http,https,deploy,webapp
INFO: server initialised (transitively) in ${jetty.base}/start.ini
INFO: http initialised in ${jetty.base}/start.ini
INFO: ssl initialised (transitively) in ${jetty.base}/start.ini
INFO: https initialised in ${jetty.base}/start.ini
INFO: webapp initialised in ${jetty.base}/start.ini
INFO: deploy initialised in ${jetty.base}/start.ini
DOWNLOAD: http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/plain/jetty-server/src/test/config/etc/keystore?id=master to ${jetty.base}/etc/keystore
MKDIR: ${jetty.base}/webapps
INFO: Base directory was modified
$ ls -laF$ ls -laF
total 48
drwxrwxr-x. 4 joakim joakim 4096 Sep 23 06:01 ./
drwxr-xr-x. 22 joakim joakim 12288 Sep 23 06:00 ../
drwxrwxr-x. 2 joakim joakim 4096 Sep 23 06:01 etc/
-rw-rw-r--. 1 joakim joakim 5009 Sep 23 06:01 start.ini
drwxrwxr-x. 2 joakim joakim 4096 Sep 23 06:01 webapps/
此时:
etc/keystore
文件替换为您的SSL密钥库。jetty.http.port
)jetty.https.port
)jetty.sslContext.
开头的键)完成后,运行Jetty ..
$ cd /opt/jetty/my.base
$ java -jar ../jetty-distribution-9.3.3.v20150827/start.jar
2015-09-23 06:05:40.619:INFO::main: Logging initialized @272ms
2015-09-23 06:05:40.764:INFO:oejs.Server:main: jetty-9.3.3.v20150827
2015-09-23 06:05:40.779:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:///home/joakim/code/jetty/distros/my.base/webapps/] at interval 1
2015-09-23 06:05:40.790:INFO:oejs.ServerConnector:main: Started ServerConnector@1718d616{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2015-09-23 06:05:40.810:INFO:oejus.SslContextFactory:main: x509=X509@7e0babb1(jetty,h=[jetty.eclipse.org],w=[]) for SslContextFactory@6debcae2(file:///home/joakim/code/jetty/distros/my.base/etc/keystore,file:///home/joakim/code/jetty/distros/my.base/etc/keystore)
2015-09-23 06:05:40.810:INFO:oejus.SslContextFactory:main: x509=X509@5ba23b66(mykey,h=[],w=[]) for SslContextFactory@6debcae2(file:///home/joakim/code/jetty/distros/my.base/etc/keystore,file:///home/joakim/code/jetty/distros/my.base/etc/keystore)
2015-09-23 06:05:41.026:INFO:oejs.ServerConnector:main: Started ServerConnector@305fd85d{SSL,[ssl, http/1.1]}{0.0.0.0:8443}
2015-09-23 06:05:41.027:INFO:oejs.Server:main: Started @680ms
好奇你的服务器配置是什么样的?运行这个......
$ cd /opt/jetty/my.base
$ java -jar ../jetty-distribution-9.3.3.v20150827/start.jar --list-config