此刻我試圖改進我的tomcat知道如何。我試圖用SSL建立tomcat。 這個想法是,我得到了/ app不需要任何授權的路徑,以及需要基本身份驗證的路徑/ admin。我想它只是缺乏關於SSL的一般知識,我不知道會發生什麼。Tomcat SSL https端口問題
當我使用url http://localhost:8080/myapp/app/
它的作品,它顯示我的網頁。現在我將/ app更改爲/ admin。之後,我的網址是https://localhost/myapp/admin
,它不工作,因爲8443端口丟失。我不明白爲什麼它會自動更改爲https,但在此之後端口丟失?我的問題是什麼?如何解決?
任何幫助,高度讚賞:)
我的server.xml:
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on"/>
<Listener className="org.apache.catalina.core.JasperListener"/>
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
/>
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="${catalina.home}/myapp.keystore"
keystorePass="histackoverflow"/>
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.MemoryRealm" />
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b"/>
</Host>
</Engine>
</Service>
我的web.xml文件看起來像這樣:
<servlet>
<servlet-name>MyApp REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>main.ch.myapp.resource.app</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Myapp REST Service</servlet-name>
<url-pattern>/app-api/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>MyApp Admin REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>main.ch.myapp.resource.admin</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyApp Admin REST Service</servlet-name>
<url-pattern>/admin-api/*</url-pattern>
</servlet-mapping>
<security-constraint>
<web-resource-collection>
<web-resource-name>MyApp Admin</web-resource-name>
<url-pattern>/admin/*</url-pattern>
<url-pattern>/admin-api/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
端口8443可用時,我添加它。但是,我可以配置它在IM上使用https時自動切換端口嗎? – NDY 2014-09-02 13:11:08
@Andy我不確定我是否正確理解你的問題。更改爲https時,您重定向到的端口是在連接器的redirectPort屬性中配置的端口。你應該得到這樣的網址:https:// localhost:8443/myapp/admin你可以發佈你的server.xml配置嗎? – 2014-09-02 13:24:42
Ty爲您提供幫助。我添加了server.xml。我猜你確實明白我的意思。當我添加8443到我的網址,它的作品。但是當我在將URL更改爲/ admin後重定向到https://時,端口不會更改爲8443. – NDY 2014-09-02 13:41:28