登录linux机器,centos自带openssl

openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
cp server.key server.key.or
openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

1 flask自身配置https
flask启动按照下面进行配置

    app.run(host='0.0.0.0',port=5000,debug=True,ssl_context=('./server.crt','./server.key'))

2 nginx配置https
一般情况并不会由flask自己做https,总需要nginx做反向代理,进行内外网隔离。故可以在nginx中增加配置

server {listen 443 ssl;client_max_body_size 100M;#mycomserver_name www.dzmsoft.com ;charset utf-8; ssl on;#ssl_certificate /application/nginx/nginx/conf/eds_ca/server.crt;#ssl_certificate_key /application/nginx/nginx/conf/eds_ca/server.key;ssl_certificate /application/nginx/nginx/conf/mycert.pem;ssl_certificate_key /application/nginx/nginx/conf/server.key;ssl_session_cache shared:SSL:10m;ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;ssl_prefer_server_ciphers on;index index.jsp default.jsp index.do default.do index.html index.htm index.php forum.php;access_log  logs/dzmsoft_access.log main;location / {proxy_pass http://dzmsoft_p;}location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico|svg|flv|xml)(.*)${expires 15d;proxy_pass http://dzmsoft_p;}location ~ .*\.(js|css|gzcss|gzjs)(.*)${expires 1d;proxy_pass http://dzmsoft_p;}location /(WEB-INF)/ {deny all;}location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico|svg|flv|js|css|gzcss|gzjs)?${if (-f $request_filename) {expires 1d;break;}}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}
}

这时flask的启动,应该是

app.run(host='0.0.0.0',port=5000,debug=True)

这里有一点需要注意,nginx配置了https了,那么flask是可以不用配置的https了。
另外下面的配置,也代表了nginx转发请求到flask的web服务是http的,

location / {proxy_pass http://dzmsoft_p;}

如果proxy_pass https://dzmsoft_p;,那么就要求flask也应该是https的,否则接口协议转换就会出现异常,提示HTTP/0.9的问题,以及nginx出现502的问题,和flask接收到乱码。
因为nginx负责转发,而且nginx配置了https,那么nginx已经做了协议转换,就不需要flask再多次一举,故这里配置http即可。
3 python调用https请求示例
重点是verify=False配置。

import requests
import json
requests.packages.urllib3.disable_warnings()
edata ={"code" : str(4201),'paper': str(1)
}
r = requests.post('https://www.dzmsoft.com/api/edata',params = edata, verify=False)try:dic_source = json.loads(r.text)# print(len(dic_source['_source']))print("总共查询到{}条数据".format(dic_source['total']))
except:print(r.text)

flask配置https相关推荐

  1. python+flask 配置https网站ssl安全认证

    目录 综述: 方法1:openssl 准备步骤 具体实施 方法2:阿里云或者宝塔免费申请(推荐) 步骤 1.准备步骤 阿里云 宝塔 python+flask子域名访问设置 1.给子域名添加DNS解析 ...

  2. Ubuntu 17.04 编译安装 Nginx 1.9.9 配置 https 免费证书

    Ubuntu 17.04 编译安装 Nginx 1.9.9 配置 https 免费证书 安装 Nginx 安装依赖 $ apt-get update $ apt-get install build-e ...

  3. apache http配置https

    apache http配置https <一,Lamp系统搭建> yum install httpd httpd-devel mysql mysql-server mysql-devel p ...

  4. Nginx配置https,反向代理多实例tomcat的操作记录

    案例说明: 前面一层nginx+Keepalived部署的LB,后端两台web服务器部署了多实例的tomcat,通过https方式部署nginx反向代理tomcat请求.配置一如下: 1)LB层的ng ...

  5. 解决微信小程序配置https不成功问题

    解决微信小程序配置https不成功问题 参考文章: (1)解决微信小程序配置https不成功问题 (2)https://www.cnblogs.com/ant-jmf17/p/8056989.html ...

  6. nginx 配置https 并解决重定向后https协议变成了http的问题

    nginx 配置https 并解决重定向后https协议变成了http的问题 参考文章: (1)nginx 配置https 并解决重定向后https协议变成了http的问题 (2)https://ww ...

  7. 配置https后访问返回403 forbidden

    今天在配置https的时候配置好,http能访问,https访问返回403 forbidden: 网上找了很多,改nginx.conf的user的 修改配置文件的 其实就是权限问题,是网站根目录的权限 ...

  8. iOS APP配置HTTPS流程

    您的APP启用HTTPS了吗?距离2017年1月1日"苹果iOS强制要求HTTPS连接"还有不到1个月的时间,是否支持HTTPS直接影响APP能否在苹果商店顺利上架.本文将帮助您更 ...

  9. 关于NodeJS配置HTTPS服务、阿里云申请HTTPS证书

    最新一直在折腾小程序 我是前后台一起做,前台不必说是微信的小程序,后端的用的是NODEJS. 所以就说一下NODEJS如何配置HTTPS服务 我的NODE用的是Express框架 直接上代码: 最重要 ...

最新文章

  1. vue data数据修改_史上最强vue总结,万字长文
  2. javascript 生成一个一亿长度的随机数组,从中排列出最大的1000个项;
  3. HEALTHY LIFE OPENCART 自适应主题模板 ABC-0133
  4. Android环信爬坑指北(二)头像昵称好友备注显示
  5. android消息机制
  6. AI入门:无门槛可以玩的神经网络
  7. Java按规则生成唯一编号
  8. 再见,金庸;再见,江湖
  9. linux-headers,如何升级linux-headers-generic?
  10. vs2008 生成项目xml文件和路径配置
  11. 用于线程间的同步与互斥-信号量sem
  12. LeetCode Letter Combinations of a Phone Number
  13. javascript原生代码实现轮播图片
  14. Java中的动态代理
  15. 使用Domain-Driven创建Hypermedia API
  16. 胡昊—第8次作业--继承
  17. Android读书笔记(一)
  18. R包ggalluvial绘制冲击图(alluvial diagram)
  19. linux怎么共享存储,什么是ISCSI,及Linux下怎么样通过ISCSI实现共享存储
  20. 基于MSP432控制的红外循迹爬坡小车设计报告

热门文章

  1. Android构建系统级应用静默授权,静默安装
  2. Jupyter notebook汉化如何调回英文?
  3. warning C4290: 忽略C++ 异常规范,但指示函数不是__declspec(nothrow)
  4. python队列(deque)
  5. geoserver图层展示
  6. 新经济业态下的搬家物流服务要完善信用体系建设
  7. Xilinx FPGA BRAM使用方法
  8. C++ (生成二维码,扫描有惊喜)
  9. 驯服烂代码_驯服Tomcat:Tomcat 5的过滤技巧
  10. 北京-京东-Java实习面经(附答案)