# 1panel + docker-openresty + discourse + cloudflare 使用socket连接 显示真实用户IP

**URL:** <https://www.sunai.net/t/topic/754>\
**Category:** IT\
**Tags:** cloudflare, 1panel, docker, openresty, discourse\
**Created:** [2025 年6 月 20 日 12:43 UTC](https://www.sunai.net/t/topic/754 "2025-06-20T12:43:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![wood](https://www.sunai.net/user_avatar/www.sunai.net/wood/32/1032_2.png) [@wood](https://www.sunai.net/u/wood)\
发布日期： [2025 年6 月 20 日 12:43 UTC](https://www.sunai.net/t/topic/754/1 "2025-06-20T12:43:51Z")

</div>

nginx使用socket代理discourse, 而不是使用端口代理, 优势在于:

- 提高安全和性能, 少一次 TCP stack
- discourse官方推荐
- 不暴露无谓端口
- UNIX socket 比本地网络通信（比如 localhost:3000）效率更高，省略网络协议栈

## Discourse

如果是已部署的修改, 需要重建app `/var/discourse/launcher rebuild app`

`app.yml`

```yml
templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  ## Uncomment the next line to enable the IPv6 listener
  #- "templates/web.ipv6.template.yml"
  - "templates/web.ratelimited.template.yml"
  - "templates/cloudflare.template.yml"
  - "templates/web.socketed.template.yml"
  ## Uncomment these two lines if you wish to add Lets Encrypt (https)
  #- "templates/web.ssl.template.yml"
  #- "templates/web.letsencrypt.ssl.template.yml"

## 此容器应暴露哪些 TCP/IP 端口？
## 如果您希望 Discourse 与另一个 Web 服务器（如 Apache 或 nginx）共享端口，
## 请参阅 https://meta.discourse.org/t/17247 获取详细信息
expose:
  #- "2080:80" # http
  #- "2443:443" # https

~~~~~~

```

## 1panel

需要修改`openresty`的compose.yml

` - /var/discourse:/var/discourse`

![Pasted image 20250620202924](https://i.czl.net/b2/img/2025/06/68555793d93fe.png)

## openresty

> 另外建议从 **源文** 里把`no-cache`头给删除掉, 让discourse控制`Cache-Control`.
> 
> 吐槽一下: 1panel的openresty添加了很多不需要的配置, 比如openresty的根缓存, 导致之前discourse app搜不到站点. 看这个: [https://www.sunai.net/t/topic/300](https://www.sunai.net/t/topic/300)

`unix:/var/discourse/shared/standalone/nginx.http.sock:`

![Pasted image 20250620203011](https://i.czl.net/b2/img/2025/06/68555795a4a5c.png)

## 成果

不再是cloudflare的IP地址了

_不过好像发现用户头像图片加载有点问题, 不太确定, 再看看_

![Pasted image 20250620203436](https://i.czl.net/b2/img/2025/06/685557972928e.png)
