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 &quot;%r&quot; %s %b" />
      </Host>
    </Engine>

  </Service>

4、结束

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

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

时间: 2024-12-04 16:30:31

Nginx+Tomcat配置https的相关文章

Linux下 nginx+tomcat配置https的总结和遇到的坑

证书的获取略 服务器的端口443确保外界网络能够进行访问. 是否配置https: nginx:是 tomcat:否 1.首先查看nginx是否支持SSL. 参考链接: 实战http切换成https 查看nginx支持SSL [[email protected] bin]# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.13.3 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) b

nginx + tomcat配置https的两种方法

# The frist method: - Nginx and Tomcat using HTTPS: 1. nginx configuration: upstream test { server 172.16.7.30:8443 weight=1; } upstream master { server 172.16.7.31:8443 weight=1; } server { listen 80; server_name test.hbc315.com master.hbc315.com; r

图文:CentOS 下对 Nginx + Tomcat 配置 SSL 实现服务器 / 客户端双向认证

1. 安装 nginx 1.1 nginx 包及其依赖包下载 出于模块的依赖性,Nginx 依赖以下三个包: gzip 模块需要 zlib 库(http://www.zlib.net/): rewrite 模块需要 pcre 库(http://www.pcre.org/): ssl 功能需要 openssl 库(http://www.openssl.org/): 分别下载它们的最新稳定版(截至本文最新稳定版分别是 zlib-1.2.8.tar.gz.pcre-8.36.tar.gz.openss

Centos7下Nginx+Tomcat配置反向代理,使用memcached解决session一致性问题

一.session一致性问题 使用集群方案解决网站高并发问题时,就会部署多台应用服务器.当用户第一次通过客户端(如:浏览器)访问服务器时,服务器会创建对应的session, 使用Nginx反向代理,假如用户A第一次访问站点,被反向代理到服务器一处理,服务器一创建对应sessionA记录信息,用户A再次访问站点时,被反向代理到服务二处理, 而服务器二没有记录用户A的session信息,就会新创建sessionB,导致用户A之前操作丢失. 我们可以通过让多个服务器统一到同一个地方新建session和

用tomcat配置https自签名证书,解决 ios7.1以上系统, 苹果inHouse发布

用tomcat配置https自签名证书,解决 ios7.1以上系统苹果inHouse发布不能下载安装的问题教程,话说,我其实最讨厌配置某某环境了,因为某一个小环节一旦出错,你的所有工作往往会功亏一篑,而且蛋疼到不行也不知道哪里出了错,我发布的的这个福利,虽然网上也有很多,但是都很零碎,有的资料还有错误,有的资料又不全,你说这样的情况,怎么不让我们搞的头疼,不过在此感谢哪些热心提供资料的人,现在既然我把它弄好了,就为大家做做贡献吧. 我目前给大家展示的是windowserver2003环境下搭建的

tomcat配置https协议

tomcat配置https协议 1.找到本地jdk底下的bin目录,bin目录底下存在文件keytool.exe(在bin目录下空白处,按住shift右击,打开命令窗口,如下图) 2.在cmd的命令窗口,输入命令(keytool -genkeypair -alias "tomcat" -keyalg "RSA" -keystore "D:\tomcat.keystore" ) 根据提示依次输入: 密钥库口令:123456(这个密码非常重要) 名字

tomcat配置https自签名证书(keytool生成)

tomcat配置https自签名证书(keytool生成) 生成keystore keytool -genkeypair -alias "server" -keyalg "RSA" -validity "365" -keystore "/app/webapp/tomcat/https/server.keystore" [[email protected] https]$ pwd /app/webapp/tomcat/https

用keytool制作证书并在tomcat配置https服务(四)

用keytool制作证书并在tomcat配置https服务(一) 用keytool制作证书并在tomcat配置https服务(二) 用keytool制作证书并在tomcat配置https服务(三) 上一篇我们实现了服务端自己模拟CA认证,那么有个问题. 一个客户端和服务端对接就需要把这个客户端的证书拿来导入到服务端的密钥库中.那么很多客户端要对接,就要多次导入. 可以这样,让客户端发送证书的csr文件给我们,我们用模拟的CA密钥库对客户端证书也进行签名颁发. 然后把签名后的证书发送给他,让他自己

Nginx+tomcat实现https访问(tomcat不配ssl证书)

用户端与Nginx通讯使用https,Nginx与tomcat通讯可以只使用http,简化证书配置. Nginx端配置nginx.conf user nginx; worker_processes  2; error_log  logs/error.log; #error_log  logs/error.log  notice; #error_log  logs/error.log  info; pid /usr/local/nginx/nginx.pid; events {     worke