certs=(X509Certificate[])request.getAttribute("javax.servlet.request.X509Certificate");
这段永远都是null不知道是哪里问题?nginx?还是tomcat?
网上搜索了不少信息,但是都没有解决,有人直接用tomcat来当https服务器是可以解决,但是我真不想那么做
nginx用http和https打开tomcat的页面都正确了,并且也弹出了证书选择的对话框,但是服务端就是不能获取客户端的认证证书信息
这段是NGINX的配置文件的
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
}
upstream tomcat {
server 192.168.2.114:8080 fail_timeout=0;
}
# HTTPS server
#
server {
listen 443 ssl;
server_name localhost;
ssl_certificate d:/ssl/server.crt;
ssl_certificate_key d:/ssl/server.key;
ssl_client_certificate d:/ssl/ca.crt;
ssl on;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_verify_client on;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
# note, there is not SSL here! plain HTTP is used
client_max_body_size 16m;
client_body_buffer_size 128k;
proxy_pass http://tomcat/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_next_upstream off;
proxy_connect_timeout 30;
proxy_read_timeout 300;
proxy_send_timeout 300;
}
}
}
这段是tomcat的
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
scheme="https"
proxyName="192.168.2.114"
proxyPort="443" />
<Valve className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="x-forwarded-for"
remoteIpProxiesHeader="x-forwarded-by"
protocolHeader="x-forwarded-proto"/>
自己搜尋了下證書傳遞,似乎找到這麼一篇,還沒經過驗證,可能可以解決這個問題
證書層級結構
伺服器結構
tomcat不要求認證客戶端,nginx要求認證客戶端
tomcat配置注意點
tomcat的伺服器憑證的CN必須為tomcat_backend
nginx配置注意點
使用openssl從pfx檔案匯出pem格式公鑰
openssl pkcs12 -clcerts -nokeys -in cert.p12 -out cert.pem
使用openssl從pfx檔案匯出pem格式私鑰
openssl pkcs12 -nocerts -nodes -in cert.p12 -out private.pem
使用openssl產生CA憑證鏈
將根CA和中級CA的公鑰憑證匯出,如匯出後檔案名稱分別為root.pem ca.pem
將root.pem ca.pem合併成一個文件,ca.pem在前,root.pem在後
cat ca.pem >> chain.pem
cat root.pem >> chain.pem
nginx server段配置
將客戶端憑證透過http頭傳遞給後端的tomcat。在proxy.conf檔中配置
關於如果產生CA證書、客戶端證書、伺服器證書,請參閱 《在JEE專案中實施SSL雙向認證》
在JEE計畫中實施SSL雙向認證