nginx配https转发

1、生成证书

创建私钥 长度2048

openssl genrsa -out privkey.pem 2048
##完成后会在当前目录生成私钥文件

自己制作证书

openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095

需要输入信息如下

字段说明示例
CountryISO国家代码(两位字母)CN
State or Provine Name所在省份LiaoNing
Locality Name所在城市ShenYang
Organization Name公司名称PuFei
Organization Unit Name部门名称IT Dept
Common Name申请证书域名www.baidu.com
Email Address电子邮箱(可以不输入)-
A challenge password加密证书请求密码(可以不输入)-

2、配置https

# 配置转发到harbor
server {
    listen 80;
    listen 443 ssl http2;
    server_name harbor.dongriaf.com;
    ssl_certificate         /etc/nginx/cert/cacert.pem; #pem证书路径
    ssl_certificate_key     /etc/nginx/cert/privkey.pem; #pem证书key路径
    ssl_session_timeout     5m; #会话超时时间
    ssl_ciphers     ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #加密算法
    ssl_protocols   TLSv1 TLSv1.1 TLSv1.2; #SSL协议
    ssl_prefer_server_ciphers on;

    location / {
        # proxy_pass http://localhost:5050;
        proxy_pass https://localhost:6443; # 转发到harbor的https端口
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

3、配置https并且支持websocket

# websocket 配置变量
map $http_upgrade $connection_upgrade {
  default upgrade;
  ''      close;
}

# 配置转发去rancher
server{
  listen 80;
  listen 443 ssl http2;

  server_name rancher.dongriaf.com;

  ssl_certificate         /etc/nginx/cert/cacert.pem; #pem证书路径
  ssl_certificate_key     /etc/nginx/cert/privkey.pem; #pem证书key路径
  ssl_session_timeout     5m; #会话超时时间
  ssl_ciphers     ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #加密算法
  ssl_protocols   TLSv1 TLSv1.1 TLSv1.2; #SSL协议
  ssl_prefer_server_ciphers on;

  location / {
        proxy_http_version 1.1; #代理使用的http协议
        proxy_set_header Host $host; #header添加请求host信息
        proxy_set_header X-Real-IP $remote_addr; # header增加请求来源IP信息
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 增加代理记录
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_pass http://localhost:5060; #服务A访问地址
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值