ssl证书引入

nginx引入ssl证书是将http升级为https访问

首先需要在nginx的根目录下的nginx.conf文件夹中配置ssl证书和key文件夹

例如

	server {
	listen 3000 ssl;    
	server_name localhost;  //要配置证书的域名
	ssl_certificate /web_cert/your_certificate.crt;   //ssl证书在本地的文件地址
	ssl_certificate_key /web_cert/your_private_key.key;   //ssl证书在本地的文件地址
	<!-- 如果是http请求那么就跳转到https页面 -->
    if ($scheme = http) {
        return 301 https://$host$request_uri;
    }

	location / {
		root /home/root1/17/dist;
		index index.html index.htm;
	}		
	location /live {
		types {
				application/vnd.apple.mpegurl m3u8;
				video/mp2t ts;
			}
				alias /home/root1/17/video_collect/video_PullFlow;
				add_header Cache-Control no-cache;
				add_header Access-Control-Allow-Origin *;
		}
}

修改了nginx.conf后需要重启nginx

sudo nginx -t   # 检查配置文件语法是否有错

sudo nginx           # 启动nginx

sudo nginx -s reload # 重新加载

sudo nginx -s stop   # 关闭nginx

配置完nginx后需要在服务中也配置ssl证书(保证服务也是在https上运行)

例如fastapi是在入口文件中配置

    config = Config(app=app, loop=loop, host='0.0.0.0', port=443, log_level="info",ssl_keyfile=ssl_keyfile,ssl_certfile=ssl_certfile)
    ser = Server(config=config)

这样就可以实现http升级为https访问了

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值