实战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匹配;

  最后“/”通用匹配

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值