转自
关键字: tomcat, ssl, tcnative, tomcat-users
1.apr
许多朋友可能在启动tomcat的时候都会看到类似这样的信息:
出现这种情况是这表示没有找到APR
简要解决办法:去 http://tomcat.heanet.ie/native/ 下载编译好的tcnative-1.dll文件,目前最新为1.1.14,拷贝至jdk/bin下,再启动就可以成功加载APR了。
2.URIEncoding
有时候在做开发的时候经常发现文本框输入的中文到了程序中成了乱码,其实是因为在端口监听部分缺少编码。
解决方法如下:
原始部分
8080端口上
修改后
8009端口 ajp跳转服务上,关于这个端口在apache http 做跳转时,要相当注意
修改后
这样,服务器得到的中文字符就不会再有乱码了。
3.设置Tomcat管理员帐号
修改tomcat-users.xml文件,在 </tomcat-users>的标签前添加一行
让tomcat用户拥有管理员权限。
4.设置SSL
首先,我们要创建密钥:
此时,用户主目录下会生成一个 .keystore文件。
然后,我们配置server.xml文件,找到SSLEnabled="true"所在的标签,将其解除注释,同时填补两个属性:
1.keystoreFile="C:/Users/Zlex/.keystore"
2.keystorePass="123456"
keystoreFile 指的是你的密钥文件存储的路径,keystorePass指的是你的密码。
举例如下:
许多朋友可能在启动tomcat的时候都会看到类似这样的信息:
- org.apache.catalina.core.AprLifecycleListener init
- 信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:/Java/jre/bin;.;C:/WINDOWS/Sun/Java/bin;C:/WINDOWS/system32;C:/WINDOWS
出现这种情况是这表示没有找到APR
简要解决办法:去 http://tomcat.heanet.ie/native/ 下载编译好的tcnative-1.dll文件,目前最新为1.1.14,拷贝至jdk/bin下,再启动就可以成功加载APR了。
- org.apache.catalina.core.AprLifecycleListener init
- 信息: Loaded Apache Tomcat Native library 1.1.14.
- org.apache.catalina.core.AprLifecycleListener init
- 信息: APR capabilities: IPv6 [false], sendfile [true], accept filters [false], random [true].
2.URIEncoding
有时候在做开发的时候经常发现文本框输入的中文到了程序中成了乱码,其实是因为在端口监听部分缺少编码。
- URIEncoding="UTF-8"
解决方法如下:
原始部分
8080端口上
- <Connector port="8080" protocol="HTTP/1.1"
- connectionTimeout="20000"
- redirectPort="8443" />
修改后
- <Connector port="8080" protocol="HTTP/1.1"
- connectionTimeout="20000"
- redirectPort="8443" URIEncoding="UTF-8" />
8009端口 ajp跳转服务上,关于这个端口在apache http 做跳转时,要相当注意
- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
修改后
- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8" />
这样,服务器得到的中文字符就不会再有乱码了。
3.设置Tomcat管理员帐号
修改tomcat-users.xml文件,在 </tomcat-users>的标签前添加一行
- <user username="tomcat" password="tomcat" roles="admin,manager"/>
4.设置SSL
首先,我们要创建密钥:
- keytool -genkey -alias tomcat -keyalg RSA
此时,用户主目录下会生成一个 .keystore文件。
然后,我们配置server.xml文件,找到SSLEnabled="true"所在的标签,将其解除注释,同时填补两个属性:
1.keystoreFile="C:/Users/Zlex/.keystore"
2.keystorePass="123456"
keystoreFile 指的是你的密钥文件存储的路径,keystorePass指的是你的密码。
举例如下:
- <!--
- Define a SSL HTTP/1.1 Connector on port 8443 This connector uses the
- JSSE configuration, when using APR, the connector should be using the
- OpenSSL style configuration described in the APR documentation
- -->
- <!-- -->
- <Connector
- SSLEnabled="true"
- clientAuth="false"
- keystoreFile="C:/Users/Zlex/.keystore"
- keystorePass="123456"
- maxThreads="150"
- port="8443"
- protocol="HTTP/1.1"
- scheme="https"
- secure="true"
- sslProtocol="TLS" />