Nginx代理https(使用自签证书)

2 篇文章 0 订阅
1 篇文章 0 订阅

Linux中使用nginx代理https

生成自签名证书

# 生成一对秘钥,把公钥做成证书
[root@localhost crt]# openssl  genrsa -out /home/ca.key 2048
Generating RSA private key, 2048 bit long modulus
....................................+++
.........+++
e is 65537 (0x10001)
[root@localhost crt]# ls
[root@localhost crt]# openssl  genrsa -out /home/crt/ca.key 2048
Generating RSA private key, 2048 bit long modulus
.......................................................................................................................+++
.............................................................................................+++
e is 65537 (0x10001)
[root@localhost crt]# ls
ca.key

# 生成证书CRT
[root@localhost crt]# openssl req -new  -x509 -key  /home/crt/ca.key  -out /home/crt/server.crt  -days 365
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:l^H^H^H
string is too long, it needs to be less than  2 bytes long
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:GS
Locality Name (eg, city) [Default City]:LZ
Organization Name (eg, company) [Default Company Ltd]:LDEY
Organizational Unit Name (eg, section) []:YF
Common Name (eg, your name or your server's hostname) []:CZD
Email Address []:2574920008@qq.com
[root@localhost crt]# ls
ca.key  server.crt

 

生成成功以后 /home目录下生成ca.key和server.crt文件

此时配置Nginx如下:

 server {
	  listen 443 ssl;
	  root /;
	  server_name  102.108.10.30;
	  ssl_certificate   /home/server.crt;
	  ssl_certificate_key  /home/ca.key;
	  ssl_session_timeout 5m;
	  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
	  location / {
			proxy_pass https://182.63.200.29:8090/;
        }
	}

重启Nginx: service nginx restart

此时在次访问:

详情参考Nginx 配置 HTTPS自签名证书 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值