先唠叨一下http2新的东西,tomcat9还有最新浏览器除ie外多数都支持,在浏览器开发工具选项中可以看到。
tomcat9坑爹的配置,说实话他提供了serverx.xml中提供了两种配置方式一种为原来的tomcat配置,一种为sslconfig配置方式,两种方式都需要先生成证书,利用jdk->keytool加上命令行然后重生成的证书store中export中导出你需要证书命令很多你可以help一下,然后可以利用openssl工具进行证书的转换你需要的格式,填写到配置文件中,这些是思路具体网上教程安装流程走就可以了,but但是but配置3天发现https容易开启但是可但是http2在浏览器端不显示(浏览器端支持http2)。
也许自己配置的不对,所以放弃,如果公司非要玩高端看http2强烈推荐jetty进行配置,相对来说官网比较全的配置方式,命令不多,当然首先你必须了解alpn还有sdpy还有http2的特性。不说废话直接上命令:
https://www.eclipse.org/jetty/documentation/current/http2-enabling.html
https://webtide.com/introduction-to-http2-in-jetty/
这里必须jdk8以上
Table 14.1. ALPN vs. OpenJDK versions:
OpenJDK version | ALPN version |
---|---|
1.7.0u40 | 7.1.0.v20141016 |
1.7.0u45 | 7.1.0.v20141016 |
1.7.0u51 | 7.1.0.v20141016 |
1.7.0u55 | 7.1.0.v20141016 |
1.7.0u60 | 7.1.0.v20141016 |
1.7.0u65 | 7.1.0.v20141016 |
1.7.0u67 | 7.1.0.v20141016 |
1.7.0u71 | 7.1.2.v20141202 |
1.7.0u72 | 7.1.2.v20141202 |
1.7.0u75 | 7.1.3.v20150130 |
1.7.0u76 | 7.1.3.v20150130 |
1.7.0u79 | 7.1.3.v20150130 |
1.7.0u80 | 7.1.3.v20150130 |
1.8.0 | 8.1.0.v20141016 |
1.8.0u05 | 8.1.0.v20141016 |
1.8.0u11 | 8.1.0.v20141016 |
1.8.0u20 | 8.1.0.v20141016 |
1.8.0u25 | 8.1.2.v20141202 |
1.8.0u31 | 8.1.3.v20150130 |
1.8.0u40 | 8.1.3.v20150130 |
1.8.0u45 | 8.1.3.v20150130 |
1.8.0u51 | 8.1.4.v20150727 |
1.8.0u60 | 8.1.5.v20150921 |
1.8.0u65 | 8.1.6.v20151105 |
1.8.0u66 | 8.1.6.v20151105 |
1.8.0u71 | 8.1.7.v20160121 |
1.8.0u72 | 8.1.7.v20160121 |
1.8.0u73 | 8.1.7.v20160121 |
1.8.0u74 | 8.1.7.v20160121 |
This section is written assuming that a jetty base directory is being used and a demo jetty base that support HTTP/1, HTTPS/1 and deployment from a webapps directory can be created with the commands:
$ JETTY_BASE=http2-demo
$ mkdir $JETTY_BASE
$ cd $JETTY_BASE
$ java -jar $JETTY_HOME/start.jar --add-to-startd=http,https,deploy
To add HTTP/2 to this demo base, it is just a matter of enabling the http2 module with the following command:
$ java -jar $JETTY_HOME/start.jar --add-to-startd=http2
This command does not create a new connector, but instead simply adds the HTTP/2 protocol to the existing HTTPS/1 connector, so that it now supports both protocols on port 8443. To do this, it also transitively enables the ALPN module for protocol negotiation. The support for each protocol can be seen in the info logging when the server is started:
$ java -jar $JETTY_HOME/start.jar
...
2015-06-17 14:16:12.549:INFO:oejs.ServerConnector:main: Started ServerConnector@34c9c77f{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2015-06-17 14:16:12.782:INFO:oejs.ServerConnector:main: Started ServerConnector@711f39f9{SSL,[ssl, alpn, h2, h2-17, http/1.1]}{0.0.0.0:8443}
...
HTTP/2 can be enabled on the plain text connector and the server restarted with the following command:
$ java -jar $JETTY_HOME/start.jar --add-to-startd=http2c
$ java -jar $JETTY_HOME/start.jar
...
2015-06-17 14:16:12.549:INFO:oejs.ServerConnector:main: Started ServerConnector@6f32cd1e{HTTP/1.1,[http/1.1, h2c, h2c-17]}{0.0.0.0:8080}
2015-06-17 14:16:12.782:INFO:oejs.ServerConnector:main: Started ServerConnector@711f39f9{SSL,[ssl, alpn, h2, h2-17, http/1.1]}{0.0.0.0:8443}
...
alpn下载:
http://mvnrepository.com/artifact/org.mortbay.jetty.alpn/alpn-boot/8.1.7.v20160121
这些官网上都有不过是英文,但是很强大。
两个非常常见的错误1,jdk版本一定要1.8希望9以后可以支持alpn不用自己配置。
2,alpn找不到类,很棘手,因为网上找不到中文资料,所以只能硬着头皮看英文的了。
java -jar /opt/jetty/start.jar --add-to-startd=http2
org.elecipse.jetty.start.graph.GraphException: Missing referenced dependency: alpn-impl
/alpn-1
.8.0_45-internal
org.eclipse.jetty.start.graph.GraphException: Missing referenced dependency: alpn-impl
/alpn-1
.8.0_45-internal
at org.eclipse.jetty.start.graph.Graph.selectNodes(Graph.java:470)
at org.eclipse.jetty.start.graph.Graph.selectNode(Graph.java:447)
at org.eclipse.jetty.start.graph.Graph.selectNode(Graph.java:415)
at org.eclipse.jetty.start.Main.processCommandLine(Main.java:302)
at org.eclipse.jetty.start.Main.main(Main.java:74)
Usage: java -jar start.jar [options] [properties] [configs]
java -jar start.jar --help
# for more information
The Jetty log files and Google were equally unhelpful in finding a solution. But after some painful trial and error I worked out a fix.
Jetty’s implementation of HTTP2 requires ALPN support so it can communicate with TLS handshake. Java 8 currently does not support ALPN and so Jetty implements a workaround extension for various versions of OpenJDK.
The Java error is actually telling you that Jetty module alpn-impl, a requirement for http2 is looking for a file dependency that doesn’t exist. The module calling for the dependency can be found at modules/alpn.mod in your jetty home. A look into the file reveals the following.
cat /opt/jetty/modules/alpn.mod
1
2
3
4
5
6
|
[name]
alpn
[depend]
ssl
alpn-impl
/alpn-
${java.version}
|
So alpn.mod is using a constant value based on the Java version to generate the dependency name. As it turns out my install of OpenJDK (openjdk-8-jre-headless) returns an interesting version and this is what is causing the problem.
java -version
1
2
3
|
openjdk version
"1.8.0_45-internal"
OpenJDK Runtime Environment (build 1.8.0_45-internal-b14)
OpenJDK 64-Bit Server VM (build 25.45-b02, mixed mode)
|
When we take a look in modules/alpn-impl/ there is no such file as 1.8.0_45-internal.mod which matches the Java dependency error message we were receiving.
ls /opt/jetty/modules/alpn-impl
|
1
|
alpn-1.8.0_05.mod alpn-1.8.0_11.mod alpn-1.8.0_20.mod alpn-1.8.0_25.mod alpn-1.8.0_31.mod alpn-1.8.0_40.mod alpn-1.8.0_45.mod alpn-1.8.0.mod
|
Fortunately the fix is easy.
cd /opt/jetty/modules/alpn-impl/
sudo ln -s alpn-1.8.0_45.mod alpn-1.8.0_45-internal.mod
Now if we try to load the http2 module it works!
cd /opt/jetty
java -jar /opt/jetty/start.jar --add-to-startd=http2
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
ALERT: There are enabled module(s) with licenses.
The following 1 module(s):
+ contains software not provided by the Eclipse Foundation!
+ contains software not covered by the Eclipse Public License!
+ has not been audited
for
compliance with its license
Module: alpn
+ ALPN is a hosted at github under the GPL v2 with ClassPath Exception.
+ ALPN replaces
/modifies
OpenJDK classes
in
the java.sun.security.ssl package.
+ http:
//github
.com
/jetty-project/jetty-alpn
+ http:
//openjdk
.java.net
/legal/gplv2
+ce.html
Proceed (y
/N
)?
|
在start启动就好了
http://devtidbits.com/2015/06/23/jetty-9-3-http2-dependancy-issue-with-ubuntu-14-04/