work hard work smart

专注于Java后端开发。 不断总结,举一反三。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Https过程

Posted on 2020-01-28 20:18  work hard work smart  阅读(392)  评论(0编辑  收藏  举报

1、Https过程

 

 

2、Nginx配置https

1)生成私钥和公钥

 命令:openssl req -x509 -newkey rsa:2048 -nodes -sha256 -keyout localhost-privkey.pem -out localhost-cert.pem

 

 

 

2)、配置test.conf文件

server{
  listen 443;
  server_name test.com;

  ssl on;
  ssl_certificate_key ../certs/localhost-privkey.pem;
  ssl_certificate ../certs/localhost-cert.pem;

  location / {
	proxy_pass http://127.0.0.1:7080;
  	proxy_set_header Host $host;
  }
}

  

 

3) host文件配置如下(C:\Windows\System32\drivers\etc下)

 

 

 

 

4) 使用https访问

 

 说明已经配置成功

 

5) 实现访问http时,直接跳转到https

server{
  listen 80 default_server;
  listen [::]:80 default_server;
  server_name test.com;
  return 302 https://$server_name$request_uri;
}


server{
  listen 443;
  server_name test.com;

  ssl on;
  ssl_certificate_key ../certs/localhost-privkey.pem;
  ssl_certificate ../certs/localhost-cert.pem;

  location / {
	proxy_pass http://127.0.0.1:7080;
  	proxy_set_header Host $host;
  }
}