---
title: "Nginx使用stream模块实现无证书TCP反向代理HTTPS"
id: "226"
type: "post"
slug: "nginx%e4%bd%bf%e7%94%a8stream%e6%a8%a1%e5%9d%97%e5%ae%9e%e7%8e%b0%e6%97%a0%e8%af%81%e4%b9%a6tcp%e5%8f%8d%e5%90%91%e4%bb%a3%e7%90%86https"
published_at: "2019-09-28T16:22:18+00:00"
modified_at: "2019-09-28T16:24:09+00:00"
url: "https://www.hitsword.org/2019/226.html"
markdown_url: "https://www.hitsword.org/2019/226.md"
excerpt: "之前在部署小型CDN的时候实现HTTPS要一个个配置证书文件，不太好实现。 最近找到TCP反向代理方式，实现方 […]"
taxonomy_category:
  - "Nginx"
taxonomy_post_tag:
  - "CDN"
  - "HTTPS"
  - "Nginx"
  - "SSL"
  - "反向代理"
---

# Nginx使用stream模块实现无证书TCP反向代理HTTPS

之前在部署小型CDN的时候实现HTTPS要一个个配置证书文件，不太好实现。  
 最近找到TCP反向代理方式，实现方法如下：  
 先编译nginx时带上参数

```
--with-stream
```

  
 然后把下面代码放在nginx.conf文件里的http外面。  
```
##TCP by Custom
stream {
    server {
        listen 443;
        proxy_pass 192.168.1.100:443;
    }
}
```

  
 上面192.168.1.100是后端地址。  
 通过TCP反向代理方式实现缺点是后端apache无法获得真实IP地址。
