2017-06-16 38 views
6

Tôi đang cố gắng định cấu hình Cầu nối của mình bằng SSL. Bây giờ tôi chỉ bị mắc kẹt vì sao nó không kết nối trên HTTPS. Nó hoạt động tốt trên HTTP mặc dù.Docker - Chạy Jetty trên HTTPS

$ {} JETTY_HOME /etc/jetty-https.xml

<?xml version="1.0"?> 
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/config 
ure_9_3.dtd"> 

<!-- ============================================================= --> 
<!-- Configure a HTTPS connector.         --> 
<!-- This configuration must be used in conjunction with jetty.xml --> 
<!-- and jetty-ssl.xml.           --> 
<!-- ============================================================= --> 
<Configure id="sslConnector" class="org.eclipse.jetty.server.ServerConnector"> 

    <Call name="addIfAbsentConnectionFactory"> 
    <Arg> 
     <New class="org.eclipse.jetty.server.SslConnectionFactory"> 
     <Arg name="next">http/1.1</Arg> 
     <Arg name="sslContextFactory"><Ref refid="sslContextFactory"/></Arg> 
     </New> 
    </Arg> 
    </Call> 

    <Call name="addConnectionFactory"> 
    <Arg> 
     <New class="org.eclipse.jetty.server.HttpConnectionFactory"> 
     <Arg name="config"><Ref refid="sslHttpConfig" /></Arg> 
     <Arg name="compliance"><Call class="org.eclipse.jetty.http.HttpCompliance" name=" 
valueOf"><Arg><Property name="jetty.http.compliance" default="RFC7230"/></Arg></Call></Ar 
g> 
     </New> 
    </Arg> 
    </Call> 

</Configure> 

$ {} JETTY_HOME /etc/jetty-ssl.xml

<?xml version="1.0"?> 
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd"> 

<!-- ============================================================= --> 
<!-- Base SSL configuration          --> 
<!-- This configuration needs to be used together with 1 or more --> 
<!-- of jetty-https.xml or jetty-http2.xml       --> 
<!-- ============================================================= --> 
<Configure id="Server" class="org.eclipse.jetty.server.Server"> 

    <!-- =========================================================== --> 
    <!-- Add a SSL Connector with no protocol factories    --> 
    <!-- =========================================================== --> 
    <Call name="addConnector"> 
    <Arg> 
     <New id="sslConnector" class="org.eclipse.jetty.server.ServerConnector"> 
     <Arg name="server"><Ref refid="Server" /></Arg> 
     <Arg name="acceptors" type="int"><Property name="jetty.ssl.acceptors" deprecated="ssl.acceptors" default="-1"/></Arg> 
     <Arg name="selectors" type="int"><Property name="jetty.ssl.selectors" deprecated="ssl.selectors" default="-1"/></Arg> 
     <Arg name="factories"> 
      <Array type="org.eclipse.jetty.server.ConnectionFactory"> 
      <!-- uncomment to support proxy protocol 
      <Item> 
       <New class="org.eclipse.jetty.server.ProxyConnectionFactory"/> 
      </Item>--> 
      </Array> 
     </Arg> 

     <Set name="host"><Property name="jetty.ssl.host" deprecated="jetty.host" /></Set> 
     <Set name="port"><Property name="jetty.ssl.port" deprecated="ssl.port" default="8443" /></Set> 
     <Set name="idleTimeout"><Property name="jetty.ssl.idleTimeout" deprecated="ssl.timeout" default="30000"/></Set> 
     <Set name="soLingerTime"><Property name="jetty.ssl.soLingerTime" deprecated="ssl.soLingerTime" default="-1"/></Set> 
     <Set name="acceptorPriorityDelta"><Property name="jetty.ssl.acceptorPriorityDelta" deprecated="ssl.acceptorPriorityDelta" default="0"/></Set> 
     <Set name="acceptQueueSize"><Property name="jetty.ssl.acceptQueueSize" deprecated="ssl.acceptQueueSize" default="0"/></Set> 
     </New> 
    </Arg> 
    </Call> 

    <!-- =========================================================== --> 
    <!-- Create a TLS specific HttpConfiguration based on the  --> 
    <!-- common HttpConfiguration defined in jetty.xml    --> 
    <!-- Add a SecureRequestCustomizer to extract certificate and --> 
    <!-- session information           --> 
    <!-- =========================================================== --> 
    <New id="sslHttpConfig" class="org.eclipse.jetty.server.HttpConfiguration"> 
    <Arg><Ref refid="httpConfig"/></Arg> 
    <Call name="addCustomizer"> 
     <Arg> 
     <New class="org.eclipse.jetty.server.SecureRequestCustomizer"> 
      <Arg name="sniHostCheck" type="boolean"><Property name="jetty.ssl.sniHostCheck" default="true"/></Arg> 
      <Arg name="stsMaxAgeSeconds" type="int"><Property name="jetty.ssl.stsMaxAgeSeconds" default="-1"/></Arg> 
      <Arg name="stsIncludeSubdomains" type="boolean"><Property name="jetty.ssl.stsIncludeSubdomains" default="false"/></Arg> 
     </New> 
     </Arg> 
    </Call> 
    </New> 
</Configure> 

Sau khi chạy docker ps -a:

[email protected]:/home/deploy/frontend/src/app/environments# docker ps -a 
CONTAINER ID  IMAGE    COMMAND     CREATED    STATUS      PORTS           NAMES 
9bf8f257f8ac  jetty    "/docker-entrypoint.s" 2 days ago   Up 14 minutes     0.0.0.0:80->8080/tcp, 0.0.0.0:443->8443/tcp jetty 

Và cuối cùng tôi

$ {} JETTY_HOME /etc/jetty.xml

<?xml version="1.0"?> 
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd"> 

<!-- =============================================================== --> 
<!-- Documentation of this file format can be found at:    --> 
<!-- http://wiki.eclipse.org/Jetty/Reference/jetty.xml_syntax  --> 
<!--                 --> 
<!-- Additional configuration files are available in $JETTY_HOME/etc --> 
<!-- and can be mixed in. See start.ini file for the default   --> 
<!-- configuration files.           --> 
<!--                 --> 
<!-- For a description of the configuration mechanism, see the  --> 
<!-- output of:              --> 
<!-- java -jar start.jar -?          --> 
<!-- =============================================================== --> 

<!-- =============================================================== --> 
<!-- Configure a Jetty Server instance with an ID "Server"   --> 
<!-- Other configuration files may also configure the "Server"  --> 
<!-- ID, in which case they are adding configuration to the same  --> 
<!-- instance. If other configuration have a different ID, they  --> 
<!-- will create and configure another instance of Jetty.   --> 
<!-- Consult the javadoc of o.e.j.server.Server for all    --> 
<!-- configuration that may be set here.        --> 
<!-- =============================================================== --> 
<Configure id="Server" class="org.eclipse.jetty.server.Server"> 

    <!-- =========================================================== --> 
    <!-- Configure the Server Thread Pool.       --> 
    <!-- The server holds a common thread pool which is used by  --> 
    <!-- default as the executor used by all connectors and servlet --> 
    <!-- dispatches.             --> 
    <!--                --> 
    <!-- Configuring a fixed thread pool is vital to controlling the --> 
    <!-- maximal memory footprint of the server and is a key tuning --> 
    <!-- parameter for tuning. In an application that rarely blocks --> 
    <!-- then maximal threads may be close to the number of 5*CPUs. --> 
    <!-- In an application that frequently blocks, then maximal  --> 
    <!-- threads should be set as high as possible given the memory --> 
    <!-- available.             --> 
    <!--                --> 
    <!-- Consult the javadoc of o.e.j.util.thread.QueuedThreadPool --> 
    <!-- for all configuration that may be set here.     --> 
    <!-- =========================================================== --> 
    <!-- uncomment to change type of threadpool 
    <Arg name="threadpool"><New id="threadpool" class="org.eclipse.jetty.util.thread.QueuedThreadPool"/></Arg> 
    --> 
    <Get name="ThreadPool"> 
     <Set name="minThreads" type="int"><Property name="jetty.threadPool.minThreads" deprecated="threads.min" default="10"/></Set> 
     <Set name="maxThreads" type="int"><Property name="jetty.threadPool.maxThreads" deprecated="threads.max" default="200"/></Set> 
     <Set name="idleTimeout" type="int"><Property name="jetty.threadPool.idleTimeout" deprecated="threads.timeout" default="60000"/></Set> 
     <Set name="detailedDump">false</Set> 
    </Get> 

    <!-- =========================================================== --> 
    <!-- Add shared Scheduler instance        --> 
    <!-- =========================================================== --> 
    <Call name="addBean"> 
     <Arg> 
     <New class="org.eclipse.jetty.util.thread.ScheduledExecutorScheduler"/> 
     </Arg> 
    </Call> 

    <!-- =========================================================== --> 
    <!-- Http Configuration.           --> 
    <!-- This is a common configuration instance used by all   --> 
    <!-- connectors that can carry HTTP semantics (HTTP, HTTPS, etc.)--> 
    <!-- It configures the non wire protocol aspects of the HTTP  --> 
    <!-- semantic.             --> 
    <!--                --> 
    <!-- This configuration is only defined here and is used by  --> 
    <!-- reference from other XML files such as jetty-http.xml,  --> 
    <!-- jetty-https.xml and other configuration files which   --> 
    <!-- instantiate the connectors.         --> 
    <!--                --> 
    <!-- Consult the javadoc of o.e.j.server.HttpConfiguration  --> 
    <!-- for all configuration that may be set here.     --> 
    <!-- =========================================================== --> 
    <New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration"> 
     <Set name="secureScheme"><Property name="jetty.httpConfig.secureScheme" default="https" /></Set> 
     <Set name="securePort"><Property name="jetty.httpConfig.securePort" deprecated="jetty.secure.port" default="8443" /></Set> 
     <Set name="outputBufferSize"><Property name="jetty.httpConfig.outputBufferSize" deprecated="jetty.output.buffer.size" default="32768" /></Set> 
     <Set name="outputAggregationSize"><Property name="jetty.httpConfig.outputAggregationSize" deprecated="jetty.output.aggregation.size" default="8192" /></Set> 
     <Set name="requestHeaderSize"><Property name="jetty.httpConfig.requestHeaderSize" deprecated="jetty.request.header.size" default="8192" /></Set> 
     <Set name="responseHeaderSize"><Property name="jetty.httpConfig.responseHeaderSize" deprecated="jetty.response.header.size" default="8192" /></Set> 
     <Set name="sendServerVersion"><Property name="jetty.httpConfig.sendServerVersion" deprecated="jetty.send.server.version" default="true" /></Set> 
     <Set name="sendDateHeader"><Property name="jetty.httpConfig.sendDateHeader" deprecated="jetty.send.date.header" default="false" /></Set> 
     <Set name="headerCacheSize"><Property name="jetty.httpConfig.headerCacheSize" default="512" /></Set> 
     <Set name="delayDispatchUntilContent"><Property name="jetty.httpConfig.delayDispatchUntilContent" deprecated="jetty.delayDispatchUntilContent" default="true"/></Set> 
     <Set name="maxErrorDispatches"><Property name="jetty.httpConfig.maxErrorDispatches" default="10"/></Set> 
     <Set name="blockingTimeout"><Property name="jetty.httpConfig.blockingTimeout" default="-1"/></Set> 
     <Set name="persistentConnectionsEnabled"><Property name="jetty.httpConfig.persistentConnectionsEnabled" default="true"/></Set> 
     <Set name="cookieCompliance"><Call class="org.eclipse.jetty.http.CookieCompliance" name="valueOf"><Arg><Property name="jetty.httpConfig.cookieCompliance" default="RFC6265"/></Arg></Call></Set> 
    </New> 

    <!-- =========================================================== --> 
    <!-- Set the default handler structure for the Server   --> 
    <!-- A handler collection is used to pass received requests to --> 
    <!-- both the ContextHandlerCollection, which selects the next --> 
    <!-- handler by context path and virtual host, and the   --> 
    <!-- DefaultHandler, which handles any requests not handled by --> 
    <!-- the context handlers.          --> 
    <!-- Other handlers may be added to the "Handlers" collection, --> 
    <!-- for example the jetty-requestlog.xml file adds the   --> 
    <!-- RequestLogHandler after the default handler     --> 
    <!-- =========================================================== --> 
    <Set name="handler"> 
     <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection"> 
     <Set name="handlers"> 
     <Array type="org.eclipse.jetty.server.Handler"> 
      <Item> 
      <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/> 
      </Item> 
      <Item> 
      <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/> 
      </Item> 
     </Array> 
     </Set> 
     </New> 
    </Set> 

    <!-- =========================================================== --> 
    <!-- extra server options          --> 
    <!-- =========================================================== --> 
    <Set name="stopAtShutdown"><Property name="jetty.server.stopAtShutdown" default="true"/></Set> 
    <Set name="stopTimeout"><Property name="jetty.server.stopTimeout" default="5000"/></Set> 
    <Set name="dumpAfterStart"><Property name="jetty.server.dumpAfterStart" deprecated="jetty.dump.start" default="false"/></Set> 
    <Set name="dumpBeforeStop"><Property name="jetty.server.dumpBeforeStop" deprecated="jetty.dump.stop" default="false"/></Set> 

</Configure> 

Tôi khá mới để Jetty và dường như không thể tìm thấy câu trả lời trực tuyến từ tất cả các tệp này đã được tạo tự động vì vậy tôi không chắc chắn những gì tôi có thể xóa và những gì không.

Bất kỳ ý tưởng nào?

(lưu ý: trong tôi /var/lib/jetty/start.d chỉ http.ini hiện diện (không chắc chắn nếu có phải là một https.ini))

tình trạng tường lửa của tôi:

Status: active 

To       Action  From 
--       ------  ---- 
Anywhere     ALLOW  somesubnet/24 
22       ALLOW  Anywhere 
300      ALLOW  Anywhere 
3000      ALLOW  Anywhere 
3001      ALLOW  Anywhere 
3002      ALLOW  Anywhere 
3003      ALLOW  Anywhere 
80       ALLOW  Anywhere 
443      ALLOW  Anywhere 
8443      ALLOW  Anywhere 
443/tcp     ALLOW  Anywhere 
521      ALLOW  Anywhere 
80,443/tcp     ALLOW  Anywhere 
22 (v6)     ALLOW  Anywhere (v6) 
300 (v6)     ALLOW  Anywhere (v6) 
3000 (v6)     ALLOW  Anywhere (v6) 
3001 (v6)     ALLOW  Anywhere (v6) 
3002 (v6)     ALLOW  Anywhere (v6) 
3003 (v6)     ALLOW  Anywhere (v6) 
80 (v6)     ALLOW  Anywhere (v6) 
443 (v6)     ALLOW  Anywhere (v6) 
8443 (v6)     ALLOW  Anywhere (v6) 
443/tcp (v6)    ALLOW  Anywhere (v6) 
521 (v6)     ALLOW  Anywhere (v6) 
80,443/tcp (v6)   ALLOW  Anywhere (v6) 

443/tcp     ALLOW OUT Anywhere 
3000      ALLOW OUT Anywhere 
443/tcp (v6)    ALLOW OUT Anywhere (v6) 
3000 (v6)     ALLOW OUT Anywhere (v6) 

Docker lệnh tôi đã sử dụng:

docker run -d --name=jetty -p 80:8080 -p 443:8443 -v /home/deploy/backend/my-server/target/my-server-0.0.1-SNAPSHOT.war:/var/lib/jetty/webapps/root.war -v /home/deploy/backend/ssl:/etc/ssl/private jetty 

Nó chạy tốt trên http://my-server.com nhưng không tải tại https://my-server.com

+0

Bạn có thể chỉ định lỗi hiển thị trình duyệt web của bạn hoặc 'curl' không?Ngoài ra, hãy làm điều này để xem điều gì xảy ra trong mạng container: 'docker exec ss -ltn' – Robert

Trả lời

3

Ngay cả khi jetty main page on Docker Hub cho thấy rằng vùng chứa phải được chạy với docker run -d -p 80:8080 -p 443:8443 jetty, có vẻ như hình ảnh không được định cấu hình cho HTTPS theo mặc định.

Như bạn đề xuất, cần có một tệp https.ini trong /var/lib/jetty/start.d. Bạn có thể tạo một bằng cách chạy lệnh java -jar "$JETTY_HOME/start.jar" --add-to-startd=https trong vùng chứa.

Đặt lệnh này trong một Dockerfile:

FROM jetty 
RUN java -jar "$JETTY_HOME/start.jar" --add-to-startd=https 

Xây dựng hình ảnh mới:

docker build -t my-server . 

Và cuối cùng khởi động máy chủ của bạn:

docker run -d --name=jetty -p 80:8080 -p 443:8443 -v /home/deploy/backend/my-server/target/my-server-0.0.1-SNAPSHOT.war:/var/lib/jetty/webapps/root.war -v /home/deploy/backend/ssl:/etc/ssl/private my-server 

này sẽ cho phép bạn kết nối với máy chủ của bạn bằng HTTPS.

Bạn có thể tìm thêm thông tin về điều này trên this Github issue.

Các vấn đề liên quan