Nginx+Tomcat配置https
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx+Tomcat配置https相关的知识,希望对你有一定的参考价值。
nginx + Tomcat 配置 HTTPS
1、总述
浏览器和 Nginx 之间走的 HTTPS 通讯,而 Nginx 到 Tomcat 通过 proxy_pass 走的是普通 HTTP 连接。
2、Nginx配置(nginx.conf),部分
http { #HTTPS server server { listen 443 ssl; server_name goldlone.cn; #证书地址 ssl_certificate ./1_goldlone.cn_bundle.crt; ssl_certificate_key ./2_goldlone.cn.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Proto https; proxy_redirect off; proxy_connect_timeout 240; proxy_send_timeout 240; proxy_read_timeout 240; # note, there is not SSL here! plain HTTP is used proxy_pass http://127.0.0.1:8080; } } }
3、Tomcat配置(server.xml),部分
<Service name="Catalina"> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443" proxyPort="443" /> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" remoteIpHeader="x-forwarded-for" remoteIpProxiesHeader="x-forwarded-by" protocolHeader="x-forwarded-proto" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host> </Engine> </Service>
4、结束
修改配置文件时,注意红色部分
证书是腾讯云申请的免费证书:https://console.qcloud.com/ssl
以上是关于Nginx+Tomcat配置https的主要内容,如果未能解决你的问题,请参考以下文章
Nginx + Tomcat + HTTPS 配置不需要在 Tomcat 上启用 SSL 支持
tomcat 安装配置部署到nginx+tomcat+https