Nginx+Tomcat配置https
阿新 • • 發佈:2017-07-31
dir source blank location prefix targe tps suffix session
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