在Tomcat 8上启用HTTPS的问题

时间:2018-03-08 14:00:31

标签: java tomcat docker

我已经在stackoverflow上阅读了很多Q& A,并且到达了以下server.xml配置。

...
  <!--  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> -->
...
    <Connector port="8080" protocol="org.apache.coyote.http11.Http11AprProtocol" connectionTimeout="20000" redirectPort="8443" />
...
<Connector connectionTimeout="20000" maxHttpHeaderSize="1048576"
    protocol="org.apache.coyote.http11.Http11NioProtocol"
    maxThreads="200" scheme="https" secure="true"
    port="8443" clientAuth="false" sslProtocol="TLS"
    keystoreFile="/usr/local/tomcat/conf/keystore.jks"
    keystorePass="strong-pwd"
    keyAlias="tag"/>
...

不幸的是,此配置引发了以下错误。

[http-nio-8443-exec-1] org.apache.coyote.http11.Http11Processor.service Error parsing HTTP request header
 Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
 java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens
    at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:426)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:687)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)

此外,我通过以下命令将tomcat作为docker容器运行:docker run -d -it --rm -p 8443:8443 -v /root/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml docker-image

啊! HTTP端口工作正常。

我错过了其他什么吗?

2 个答案:

答案 0 :(得分:0)

为APR配置了8080:

<Connector port="8080" protocol="org.apache.coyote.http11.Http11AprProtocol" ...

但是APR听众被注释掉了:

<!--  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> -->

我不熟悉APR。我使用默认协议:

<Connector port="8080" protocol="HTTP/1.1" ... 

答案 1 :(得分:0)

嗯,我不确定我做错了什么,但是我遵循了严格针对Tomcat8的本教程并且它有效。也许我忘记了强制性属性。

https://www.itworld.com/article/2769041/development/how-to-configure-tomcat-to-always-require-https.html