zoukankan      html  css  js  c++  java
  • 实战http切换成https

     

    Server端使用Nginx + Tomcat

    Niginx SSL on

    Tomcat SSL non

    步骤:

     

    1、修改代码,将外部引用的http js css 文件修改为https,若外部链接不支持https 则需将静态文件下载到项目中 在项目中引用。

    2、将申请到的https安全证书放入NGINX目录

    3、修改Nginx配置文件,打开SSL支持,并将安全证书引入配置文件。

    4、打开nginx websocket 支持

     

    5、将js ,app中引用的websocket地址由ws改为wss

     

    6、系统会直接调用外部平台的详情页面,需要将其代理到https域名,否则页面无法访问

     

    7、./nginx -t 测试配置文件是否能够成功加载,若配置成功则重新加载niginx配置文件 ./nginx -s reload

     

    8、FASTDFS文件服务器暂时不用https处理,http文件也可以访问

     

    升级完成后测试点

    1.系统各个页面,图标能正常访问

    2.app调用接口能正常访问

    3.app,web 跟踪页图片视频正常显示

    4.锐明科技引用页面正常访问

    5.监控大屏正常访问数据显示正常

    6.外部平台能正常调用平台https接口

     

     

    注意事项:

     

     

    1、NGINX 缺少SSL模块

    在centos中,配置nginx的https时,出现如下错误。

    nginx: [emerg] unknown directive "ssl" in /usr/local/nginx/conf/nginx.conf:102

    A)到解压的nginx目录下

    ./configure --with-http_ssl_module

    当执行上面语句,出现./configure: error: SSL modules require the OpenSSL library.

    用 yum -y install openssl openssl-devel

    B)再执行./configure

    重新执行./configure --with-http_ssl_module

    make ,切记不能make install 会覆盖。

    C)把原来nginx备份

    cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

    把新的nginx覆盖旧的

    cp objs/nginx /usr/local/nginx/sbin/nginx

    出现错误时cp: cannot create regular file ‘/usr/local/nginx/sbin/nginx’: Text file busy

    用cp -rfp objs/nginx /usr/local/nginx/sbin/nginx解决

    D)测试nginx是否正确

    /usr/local/nginx/sbin/nginx -t

    (nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful)

    E)重启nginx

    /usr/local/nginx/sbin/nginx -s reload

     

    2、request.getScheme() 取到https正确的协议详解

    A)配置nginx的转发项,配置文件为nginx.conf,添加以下内容如下:

    proxy_set_header X-Forwarded-Proto  $scheme;

     

    B) 配置tomcat,配置文件为server.xml,添加内容如下:

    <Valve className="org.apache.catalina.valves.RemoteIpValve"
    remoteIpHeader="X-Forwarded-For"
    protocolHeader="X-Forwarded-Proto"
    protocolHeaderHttpsValue="https"/>

     

    3.  NGINX的匹配顺序

     

    location的语法规则如下: location [=|~|~*|^~] /uri/ { … }.

      在nginx中location分为两类:普通location和正则location。普通 location ”是以“ = ”或“ ^~ ”为前缀或者没有任何前缀的 /uri/,包括“/”;“正则 location ”是以“ ~ ”或“ ~* ”为前缀的 /uri/ 。

      那么如果一个 server 块中编写了多个 location 的时候,Nginx对于客户端请求匹配顺序如何呢?

      官网说明如下:先匹配普通location,取的最大前缀匹配,再匹配正则location,如果匹配到则按照正则匹配,如果有多个正则可以匹配到,则按照第一个匹配结果处理,如果正则匹配失败则使用普通location的最大前缀匹配。Nginx也设置了几种机制可以打断这种顺序,分别是“^~ ”、“= ”或者location精确匹配。

      简单的讲顺序如下:

      首先普通location“=”精确匹配;

      然后普通location的URL精确匹配;

      然后普通location”^~"配置;

      然后正则匹配;

      然后其他普通location匹配;

      最后“/”通用匹配

     

  • 相关阅读:
    5-python基础—获取某个目录下的文件列表(适用于任何系统)
    Automated, Self-Service Provisioning of VMs Using HyperForm (Part 1) (使用HyperForm自动配置虚拟机(第1部分)
    CloudStack Support in Apache libcloud(Apache libcloud中对CloudStack支持)
    Deploying MicroProfile-Based Java Apps to Bluemix(将基于MicroProfile的Java应用程序部署到Bluemix)
    Adding Persistent Storage to Red Hat CDK Kit 3.0 (在Red Hat CDK Kit 3.0添加永久性存储)
    Carve Your Laptop Into VMs Using Vagrant(使用Vagran把您笔记本电脑刻录成虚拟机)
    使用Python生成一张用于登陆验证的字符图片
    Jupyter notebook的安装方法
    Ubuntu16.04使用Anaconda5搭建TensorFlow使用环境 图文详细教程
    不同时区的换算
  • 原文地址:https://www.cnblogs.com/lazyInsects/p/9304176.html
Copyright © 2011-2022 走看看