certbot软件从Github直接下载,在CentOS6、7下执行都没有问题。
certbot-auto运行是会自动连接下载依赖包,启用163(http://mirrors.163.com/.help/centos.html)和epel(https://fedoraproject.org/wiki/EPEL#How_can_I_use_these_extra_packages.3F)库,提前准备好环境,更多查看https://certbot.eff.org/#centosrhel6-other
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
mv CentOS6-Base-163.repo /etc/yum.repos.d/
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
rpm -ivh epel-release-latest-6.noarch.rpm
修改CentOS6-Base-163.repo文件,将$releasever
替换为6
修改epel.repo文件,将$releasever
替换为6
,将http://download.fedoraproject.org/pub/epel
修改为https://mirrors.tuna.tsinghua.edu.cn/epel
运行以下命令生成缓存
yum clean all
yum makecache
安装git软件,也可直接从https://github.com/certbot/certbot下载
yum install git
修改/etc/sysconfig/iptables
vim /etc/sysconfig/iptables
查看是否有80、443端口允许访问记录
-A INPUT -i eth0 -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 443 -j ACCEPT
certbot-auto运行是会自动连接下载依赖包,执行过程出现问题具体分析原因
git clone https://github.com/certbot/certbot
cd certbot
certbot-auto命令在root用户下执行,certbot-auto会执行更新certbot版本和安装依赖包,执行需要联网,有时较慢
./certbot-auto certonly --standalone --email 你的邮箱 -d 你的域名
生成的证书放在/etc/letsencrypt/live/[网站域名]
下,证书有效期3个月
文件名 | 内容 |
---|---|
cert.pem | 服务端证书 |
chain.pem | 浏览器需要的所有证书但不包括服务端证书,比如根证书和中间证书 |
fullchain.pem | 包括了cert.pem和chain.pem的内容 |
privkey.pem | 证书的私钥 |
./certbot-auto renew
更新证书之后,需要执行tomcat、weblogic对应配置内容。
Apache测试版本
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 14 2016 18:04:44
修改/etc/httpd/conf.d/ssl.conf
Listen 443 https
Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/域名/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/域名/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/域名/fullchain.pem
HSTS(HTTP Strict Transport Security)的作用是强制客户端(如浏览器)使用HTTPS与服务器创建连接。
cp /etc/letsencrypt/live/域名/*.pem apache-tomcat-8.5.5/conf/
cd apache-tomcat-8.5.5/conf/
chown 用户:组 *.pem
修改conf/server.xml文件:
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true" >
<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
<SSLHostConfig>
<Certificate certificateKeyFile="conf/privkey.pem"
certificateFile="conf/cert.pem"
certificateChainFile="conf/fullchain.pem"
type="RSA" />
SSLHostConfig>
Connector>
修改nginx的配置文件/usr/local/nginx/conf/nginx.conf
,实现https转到内网tomcat的http服务,注:以下配置未实现tomcat识别来自https的请求,详细见问题3
server {
listen 8443;
server_name localhost;
ssl on;
ssl_certificate /etc/letsencrypt/live/域名/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/域名/privkey.pem;
server_name_in_redirect off;
proxy_set_header Host $host:$server_port;
proxy_connect_timeout 60s;
proxy_read_timeout 5400s;
proxy_send_timeout 5400s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
index index.html index.htm index.jsp index.do;
location ^~ /ZhsqApp/{
proxy_pass http://192.168.100.10:8080;
client_max_body_size 100m;
}
}
weblogic必须是10.3.6及以上版本,才能使用Let's Encrypt的证书,Let's Encrypt采用SHA256withRSA,低版本的不支持SHA256withRSA
执行openssl
命令生成fullchain_and_key.p12
,执行keytool
命令生成密钥库文件weblogic.jks
openssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out fullchain_and_key.p12 -name weblogic -passout pass:123456
keytool -importkeystore -deststorepass 123456 -destkeystore weblogic.jks -srckeystore fullchain_and_key.p12 -srcstoretype PKCS12 -srcstorepass 123456 -alias weblogic
privkey.pem
、fullchain.pem
为Let’s Encrypt生成文件,密码可自行修改。注-name
与-alias
别名保存一致,-passout
参数的pass:
需保留。-passout
与-srcstorepass
密码保持一致, -deststorepass
需记住在weblogic配置使用。
执行keytool
命令生成信任库文件trust.jks
keytool -importcert -alias rootCA -trustcacerts -file cert.pem -keystore trust.jks -storepass 123456
cert.pem
为Let’s Encrypt生成文件,密码可自行修改。 -storepass
需记住在weblogic配置使用。
登录weblogic控制台 -> 服务器 -> 选择服务器管理 -> 配置标签 -> 一般信息子标签页 -> 启用 SSL 监听端口 -> 修改端口7002 -> 保存
在Linux下设置端口小于1024的,需要使用管理员用户启动weblogic。
进入配置标签 -> 密钥库标签页
1. 密钥库点更改,选择定制标识和定制信任,点击保存。
1. 定制标识密钥库,填写weblogic.jks全路径
1. 定制标识密钥库类型,填写jks
1. 定制标识密钥库密码短语,填写生成密钥库时 -deststorepass
写的密码
1. 确认定制标识密钥库密码短语,填写生成密钥库时 -deststorepass
写的密码
1. 定制信任密钥库,填写trust.jks全路径
1. 定制信任密钥库类型,填写jks
1. 定制信任密钥库密码短语,填写生成信任库时 -storepass
写的密码
1. 确认定制信任密钥库密码短语,填写生成信任库时 -storepass
写的密码
进入配置标签 -> SSL标签页
1. 私有密钥别名,填写生成密钥库时的别名
1. 私有密钥密码短语,填写生成密钥库时 -deststorepass
写的密码
1. 确认私有密钥密码短语,填写生成密钥库时 -deststorepass
写的密码
点击保存
weblogic 10.3. 6 版本还需要做额外配置
,SSL标签页中,点击高级,选中使用 JSSE SSL,点击保存
重启weblogic服务,测试https访问。
主要原因是缺少中级证书。生成的LE证书后使用的需要使用fullchain.pem,打开后会发现有两段证书,第一段是LE的证书,第二段才是你网站的证书。而你只有网站的证书,而没有LE的证书。
查看http://disablessl3.com如何关闭apache、nginx的ssl3协议
tomcat修改,修改server.xml,
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true"
sslProtocol="TLS" sslEnabledProtocols="TLSv1,TLSv1.1,TLSv1.2" >
修改nginx的配置文件
修改nginx的配置文件/usr/local/nginx/conf/nginx.conf
,实现https转到内网tomcat的http服务,注:以下配置未实现tomcat识别来自https的请求,详细见问题2
server {
listen 8443;
server_name localhost;
ssl on;
ssl_certificate /etc/letsencrypt/live/域名/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/域名/privkey.pem;
server_name_in_redirect off;
proxy_set_header Host $host:$server_port;
proxy_connect_timeout 60s;
proxy_read_timeout 5400s;
proxy_send_timeout 5400s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header WL-Proxy-SSL true;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; ";
index index.html index.htm index.jsp index.do;
location ^~ /ZhsqApp/{
proxy_pass http://192.168.100.10:8080;
client_max_body_size 100m;
}
}
主要增加3处配置:
proxy_set_header X-Forwarded-Proto $scheme;
tomcat可识别参数proxy_set_header WL-Proxy-SSL true;
weblogic可识别参数add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; ";
启用HSTS功能,浏览器在63072000秒时间内默认以https请求服务server.xml
,在Engine下添加下面内容
protocolHeader="X-Forwarded-Proto"
protocolHeaderHttpsValue="https" httpsServerPort="8443"/>
request.getScheme()
的值显示https
。非443端口时,必须增加httpsServerPort配置,不然request.getServerPort()方法返回 443 域名->配置->Web应用程序
,勾选启用 WebLogic 插件
,保存 request.getScheme()
的值显示https