网站首页 > 技术教程 正文
https 服务部署
使用 HTTPS 需要生成私钥与公钥;某个文件夹中打开 git bash 输入命令:openssl req -x509 -newkey rsa:2048 -nodes -sha256 -keyout localhost-privkey.pem -out localhost-cert.pem;会生成两个文件 localhost-privkey.pem 跟 localhost-cert.pem;
这里我将生成的证书放在了 nginx 安装目录下的 certs 文件夹中。这样就完成了 https 服务的部署。
proxy_cache_path cache levels=1:2 keys_zone=my_cache:10m;
# 表示要启动一个服务
server {
# 开启 ssl 加密算法
listen 443 ssl; # 服务监听的端口-https默认使用端口
server_name localhost; # 浏览器访问的 host name
# 指定对应的证书
# 相对路径-证书存放的路径
ssl_certificate_key ../certs/localhost-privkey.pem;
ssl_certificate ../certs/localhost-cert.pem;
# 要代理的路由
location / {
# 匹配到 localhost:9999/ 代理到下面的地址
proxy_pass http://localhost:8888;
}
}
#访问 http 跳转到 https 服务
如果我们想在访问 http 的时候直跳转到 https:
# 增加服务配置 http 跳转到 https
server {
listen 8777 default_server;
listen [::]:8777 default_server; # 使用 IP 的情况下
server_name localhost;
return 302 https://$server_name$request_uri; # server_name 就是前面指定的 localhost,request_uri 就是具体访问的路径
}
# 表示要启动一个服务
server {
# 开启 ssl 加密算法
listen 443 ssl; # 服务监听的端口-https 默认使用端口
server_name localhost; # 浏览器访问的 host name
# 指定对应的证书
# 相对路径-证书存放的路径
ssl_certificate_key ../certs/localhost-privkey.pem;
ssl_certificate ../certs/localhost-cert.pem;
# 要代理的路由
location / {
# 匹配到 localhost:9999/ 代理到下面的地址
proxy_pass http://localhost:8888;
}
}
猜你喜欢
- 2024-10-09 面试题 HTTP及web服务相关(nginx apache)
- 2024-10-09 Nginx实现认证登录(nginx登录验证)
- 2024-10-09 Nginx 是如何处理 HTTP 头部的?(女飞行员余旭遗体头部图)
- 2024-09-08 nginx 安装教程(详解)(nginx安装与配置详解)
- 2024-09-08 学习Nginx,跟着阿里大牛走,一套精心整理的Nginx(PDF文档)
- 2024-09-08 nginx实现内外网访问限制(nginx 内网)
- 2024-09-08 nginx的多域http、https同时访问配置及http重定向https
- 2024-09-08 nginx httpstatus 408 研究(404 not found nginx是什么意思)
- 2024-09-08 Nginx完全指南--内容解析(三)(nginx 详解)
- 2024-09-08 Nginx http 强转https(http://cas.tjgl.teacheredu.cn)
你 发表评论:
欢迎- 最近发表
-
- Win11学院:如何在Windows 11上使用WSL安装Ubuntu
- linux移植(Linux移植freemodbus)
- 独家解读:Win10预览版9879为何无法识别硬盘
- 基于Linux系统的本地Yum源搭建与配置(ISO方式、RPM方式)
- Docker镜像瘦身(docker 减小镜像大小)
- 在linux上安装ollama(linux安装locale)
- 渗透测试系统Kali推出Docker镜像(kali linux渗透测试技术详解pdf)
- Linux环境中部署Harbor私有镜像仓库
- linux之间传文件命令之Rsync傻瓜式教程
- 解决ollama在linux中安装或升级时,通过国内镜像缩短安装时长
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)