# 无法连接到 localhost:6379 上的 Redis (Errno::EADDRNOTAVAIL)

**URL:** <https://meta.discourse.org/t/error-connecting-to-redis-on-localhost-6379-errno-eaddrnotavail/183647>\
**Category:** Self-hosting\
**Created:** [2021年三月18日 11:46 UTC](https://meta.discourse.org/t/error-connecting-to-redis-on-localhost-6379-errno-eaddrnotavail/183647 "2021-03-18T11:46:48Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2021年三月23日 23:49 UTC](https://meta.discourse.org/t/error-connecting-to-redis-on-localhost-6379-errno-eaddrnotavail/183647/26 "2021-03-23T23:49:25Z")

</div>

> [@Andrea\_Giovacchini](#):
>
> 如果我在 app.yml 中将主机名设置为 discourse.apicolturaitalianafb.it:8880，重建后访问 [http://discourse.apicolturaitalianafb.it:8880](http://discourse.apicolturaitalianafb.it:8880) 可以正常工作，但我不能就这样使用它。

所以，如果你移除反向代理后它就能工作了？那么问题就出在反向代理的配置上：wink:

> [@Andrea\_Giovacchini](#):
>
> 你尝试过的那个全新安装是直接暴露的吗？

是的！

---

<div class="post-metadata">

**Author:** ![Andrea\_Giovacchini](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/andrea_giovacchini/32/213224_2.png) [@Andrea\_Giovacchini](https://meta.discourse.org/u/Andrea_Giovacchini)\
**Post date:** [2021年三月24日 08:41 UTC](https://meta.discourse.org/t/error-connecting-to-redis-on-localhost-6379-errno-eaddrnotavail/183647/27 "2021-03-24T08:41:13Z")

</div>

@Falco 我终于找到解决方案了！之前尝试通过 HAPROXY、NGINX 和 APACHE 进行 HTTP 反向代理，虽然网站能访问，但删除问题始终存在。

昨晚我做了最后一次尝试，因为我真的很想用 Discourse，于是心想：再试一次 HTTPS 吧，虽然可能没区别，但在放弃前为什么不试试呢？

结果，使用 HTTPS 后一切完美运行。对我来说这样最好，我就把 HTTP 扔进垃圾桶吧 😂

以下是 Apache 配置的相关部分：

\u003e \u003cVirtualHost \*:443\u003e  
\u003e ServerName discourse.apicolturaitalianafb.it  
\u003e \tSSLEngine on  
\u003e \tSSLCertificateFile "/usr/local/ssl/crt/certificate.crt"  
\u003e \tSSLCertificateKeyFile "/usr/local/ssl/crt/private.key"  
\u003e \tSSLCertificateChainFile "/usr/local/ssl/crt/ca\_bundle.crt"  
\u003e \u003cLocation /\u003e  
\u003e ProxyPreserveHost On  
\u003e RequestHeader set Host "discourse.apicolturaitalianafb.it:8443"  
\u003e ProxyPass [http://discourse.apicolturaitalianafb.it:8880/](http://discourse.apicolturaitalianafb.it:8880/)  
\u003e \u003c/Location\u003e  
\u003e \u003c/VirtualHost\u003e

以及 Discourse 的 app.yml 配置：

\u003e templates:  
\u003e - "templates/postgres.template.yml"  
\u003e - "templates/redis.template.yml"  
\u003e - "templates/web.template.yml"  
\u003e - "templates/web.ratelimited.template.yml"  
\u003e # - "templates/web.socketed.template.yml"  
\u003e ## 如果希望添加 Lets Encrypt (https)，请取消下面这两行的注释  
\u003e #- "templates/web.ssl.template.yml"  
\u003e #- "templates/web.letsencrypt.ssl.template.yml"  
\u003e  
\u003e ## 此容器应暴露哪些 TCP/IP 端口？  
\u003e ## 如果您希望 Discourse 与 Apache 或 nginx 等其他 Web 服务器共享端口，  
\u003e ## 请参阅 [Run other websites on the same machine as Discourse](https://meta.discourse.org/t/17247) 了解详情  
\u003e expose:  
\u003e - "8880:80" # http  
\u003e # - "8443:443" # https

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2021年三月24日 12:03 UTC](https://meta.discourse.org/t/error-connecting-to-redis-on-localhost-6379-errno-eaddrnotavail/183647/28 "2021-03-24T12:03:27Z")

</div>

> [@Andrea\_Giovacchini](#):
>
> 我要把 HTTP 扔进垃圾桶

早就该这样了！😉

很高兴你解决了这个问题。

[上一頁](https://meta.discourse.org/t/error-connecting-to-redis-on-localhost-6379-errno-eaddrnotavail/183647.md?page=1)
