Nginx 配置用于 Tor 上的 Discourse 论坛

Hello all,

I would like to configure Discourse to be a Tor hidden service using nginx. Here is the configuration that I am trying in nginx (it doesn’t work, “server not found”):

server {
    listen unix:/var/run/nginx-onion.sock;
    server_name prostadqmwc6no3n.onion;
    location / {
        proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock:;
        proxy_set_header Host $http_host;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

In my tor.conf file I have this:

HiddenServiceDir /var/lib/tor/hidden_service/
HiddenServicePort 80 unix:/var/run/nginx-onion.sock

And in /var/lib/tor/hidden_service I have the hostname and private key files. Tor is running.

Discourse is installed and working on the clearweb, and /var/discourse/shared/standalone/nginx.http.sock exists.

If needed I’m happy to pay someone for an hour or so of work to get this running (I doubt it will take more than that, because I’m probably just being stupid).

Did you look at Template for serving through an .onion address with Docker?

Yes but honestly I can’t make head or tail of it and it seems an over-complicated approach for what I need, which is just a working nginx configuration.

你找到解决方案了吗?

另外,你是如何在 Tor 网络上为 .onion 地址部署 Discourse 论坛的?(我希望论坛仅能通过 Tor 访问)

是的,这是正常工作的配置。问题其实很简单:最初我尝试使用 socket 来托管网站,但这行不通,所以我不得不改用端口。

server {
    listen 801;
    server_name 127.0.0.1;
   location / {
        proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock:;
        proxy_set_header Host $http_host;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

感谢您的快速回复!

还有一个问题:您的服务器配置是什么(针对多少用户规模)?您是否针对 Tor 网络的性能做过任何优化?

提前感谢!

这是一台 2GB 的 Digital Ocean 虚拟机,有 105 名用户。我们未进行任何修改(除安装了一个插件,以便同时通过 Tor 和清网提供服务)。

还有一个问题,用户图片(如背景卡片、个人资料横幅等)加载时间过长是否有问题?(我猜这是因为 Tor 的原因)。不过一旦缓存后,显示就正常了。

我不太确定 Tor 用户地址是如何工作的。但对我来说,所有登录用户的 IP 都显示为 127.0.0.1,这符合我的预期,因为我在 nginx 中设置了 x-forwarded-for 头。

我不确定 Tor 用户是否在 Tor 网络本身拥有类似 IP 的标识,以及如何将其显示出来。

可能需要使用 set_real_ip_from