Nginx+Tomcat配置https

2021-06-18 03:05

阅读:279

标签:_for   ssl   lan   style   listen   cat   ack   director   pass   

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),部分

"Catalina">

    "8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="443"
               proxyPort="443" />

    "8009" protocol="AJP/1.3" redirectPort="8443" />


    "Catalina" defaultHost="localhost">
      "org.apache.catalina.realm.LockOutRealm">
        "org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      "localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
        "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" />
      

4、结束

修改配置文件时,注意红色部分

证书是腾讯云申请的免费证书:https://console.qcloud.com/ssl

 

Nginx+Tomcat配置https

标签:_for   ssl   lan   style   listen   cat   ack   director   pass   

原文地址:http://www.cnblogs.com/goldlone/p/7263791.html


评论


亲,登录后才可以留言!