zoukankan      html  css  js  c++  java
  • nginx代理tomcat

    本文记录的使用环境为 centOS7.2系统,Nginx1.10.1, tomcat8.5

    nginx已经实现 https

    试了好几次终于成功,Nginx实现了 SSL ,那么tomcat就不需要再配置 SSL 了,在这里我取消了原来tomcat的SSL配置。

    一、首先修改/usr/local/nginx/conf下的nginx.conf文件,在http 域下增加,绿色部分为主要部分。注意是在 433端口

    #服务器集群,可以增加多个
        upstream tomcat1 {
            server 127.0.0.1:8080;
        }
        server{
            #监听443端口
            listen 443;
            #对应的域名,把baofeidyz.com改成你们自己的域名就可以了,我这里用localhost是一样的
            server_name localhost;
            ssl on;
            #从腾讯云获取到的第一个文件的全路径
            ssl_certificate /etc/ssl/1_www.project.cn_bundle.crt;
            #从腾讯云获取到的第二个文件的全路径
            ssl_certificate_key /etc/ssl/2_www.project.cn.key; 
         ssl_session_timeout 5m;
         ssl_protocols TLSv1 TLSv1.
    1 TLSv1.2;
         ssl_ciphers ECDHE
    -RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
         ssl_prefer_server_ciphers on;
       #这是我的主页访问地址,因为使用的是静态的html网页,所以直接使用location就可以完成了。
         location
    / {
          #文件夹 root
    /usr/local/nginx/html;
          #主页文件 index index.html;
         }
         #这个是匹配你访问的某个项目 
            location /project/ {
                    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://tomcat1;  #修改配置,与上面tomcat1一致
            }
        }

    2、修改tomcat配置文件

    redirectPort改为443,并增加proxyPort="443"

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

    redirectPort改为443

    <Connector port="8009" protocol="AJP/1.3" redirectPort="443" />

    重启 tomcat 和 nginx 即可

     参考 https://segmentfault.com/a/1190000016584420?utm_source=tag-newest

    现在好的博文越来越少,这 篇对我帮助很大。

  • 相关阅读:
    git 删除所有提交下的某个文件
    Sublime Text 中文
    git 常用文件目录介绍
    设计模式之——单例模式
    Mysql系统知识梳理
    Spring系列之——使用了哪些设计模式
    JAVA基础之——三大特征、接口和抽象类区别、重载和重写区别、==和equals区别、JAVA自动装箱和拆箱
    集合系列问题
    做一个优秀的职场人才
    Spring系列之——Spring事务以及两大核心IOC和AOP
  • 原文地址:https://www.cnblogs.com/zeussbook/p/11238564.html
Copyright © 2011-2022 走看看