Tomcat单节点 ---【了解项-安装PFX格式证书】
1.修改tomcat配置: server.xml
-
首先需要有证书 ( 必须 )
-
将http的默认监听端口8080 修改为 80,redirect至 443
-
开启https监听器,配置证书即可。
-
将http强制跳转https ( tomcat操作,与nginx无关。)
使用新机器web03演示
[root@nfs ~]# yum install java -y
[root@nfs ~]# mkdir /soft
[root@nfs ~]# tar xf apache-tomcat-9.0.34.tar.gz -C /soft/
[root@nfs ~]# ln -s /soft/apache-tomcat-9.0.34/ /soft/tomcat
[root@nfs ~]# **cat /soft/tomcat/conf/server.xml**
-----> ?server_tls.xml
2.1 修改 localhost
<Host name="aliyun.baimei.com" appBase="webapps"
全栈https
| web1 | web2 | lb3 | |------------|------------|----------| | 172.16.1.7 | 172.16.1.8 | 10.0.0.5 |
[root@lb01 conf.d]# cat /etc/nginx/conf.d/proxy_zrlog.baimei.com.conf
upstream zrlog {
server 172.16.1.7:8080;
server 172.16.1.8:8080;
}
server {
listen 443 ssl;
server_name zrlog.baimei.com;
ssl_certificate ssl_key/server.crt;
ssl_certificate_key ssl_key/server.key;
#tomcat启动的java程序,可以直接通过proxy_pass进行负载均衡
location / {
proxy_pass http://zrlog;
include proxy_params;
}
}
server {
listen 80;
server_name zrlog.baimei.com;
return 302 https://$server_name$request_uri;
}