23

使用nginx转换HTTPS流量

 4 years ago
source link: http://www.cnblogs.com/fourther/p/12701335.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

背景

公司卖了一个产品给甲方,甲方要求部署后,要以 https 来访问。甲方提供了证书信息和私钥,记录一下部署过程。

实现

1、思路

在我们产品服务器上部署一个 nginx 、证书信息也放在这个服务器上。外界的 https 经过 nginx 变成 http 协议,大致思路如下:

6FFJBni.jpg!web

2、安装过程

(1)上传证书、私钥到服务器

  • 证书 server.pem 放于 /hand/certificate/server.pem
  • 私钥 server.key 放于 /hand/certificate/server.key ;

(2)配置 nginx.conf 文件

events {
    
}

http {
    server {
    	listen 443 ssl;
    	server_name 随意写;
    	ssl_certificate /app/test.crt;
    	ssl_certificate_key /app/test.key;
    
    	location / {
    		proxy_pass http://项目真实访问地址/;
    		proxy_redirect http://项目真实访问地址/; https://外网访问的地址/;
		}
	} 
}

ssl_certificatessl_certificate_key 配置的地址是以后 nginx 容器内部的证书、私钥地址;

proxy_redirect 是配置项目中如果有重定向请求的话,仍然进行转发;

(3)起一个 nginx 容器

docker run -v /nginx/nginx.conf:/etc/nginx/nginx.conf:ro -p 443:433 -v /hand/certificate/server.pem:/app/test.crt -v /hand/certificate/server.key:/app/test.key -d --restart=always nginx

--restart=always 防止服务器重启后,忘记开这个了

要确保把外界的证书路径给映射到容器中

至于 .ctr.pem.key 后缀应该是无所谓的

参考信息

未完待续~

为什么 https 能保证安全? stl ?

一个 https 连接过程是什么样子的?

为什么需要证书?

原博客地址


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK