请问如何修改 Discourse 端口?

想把discourse已经在用的80、443端口改一下,比如1080,10443,请问该如何操作?
目前参考 Run other websites on the same machine as Discourse - sysadmin - Discourse Meta 修改了’app.yml’,改成了

expose:

 - “1080:80”

rebuild以后终端显示正常

使用nginx魔改的OpenResty做反向代理,这套工具在其他服务很正常,比如http://144.217.90.95:1200,代理成了http://rsshub.beginner.center,已经可以正常访问,但代理discourse时出现异常,把http://144.217.90.95:1080代理成http://forum.beginner.center却报错502

查看了OpenResty(nginx魔改)后台报错日志

2024/04/17 11:26:27 [error] 294#294: *5624 connect() failed (111: Connection refused) while connecting to upstream, client: 58.153.170.44, server: forum.beginner.center, request: "GET /service-worker.js HTTP/2.0", upstream: "http://144.217.90.95:1080/service-worker.js", host: "forum.beginner.center", referrer: "https://forum.beginner.center/service-worker.js"
2024/04/17 11:27:55 [error] 338#338: *5959 connect() failed (111: Connection refused) while connecting to upstream, client: 223.104.44.53, server: forum.beginner.center, request: "GET / HTTP/1.1", upstream: "http://144.217.90.95:1080/", host: "forum.beginner.center"
2024/04/17 11:27:56 [error] 338#338: *5959 connect() failed (111: Connection refused) while connecting to upstream, client: 223.104.44.53, server: forum.beginner.center, request: "GET /favicon.ico HTTP/1.1", upstream: "http://144.217.90.95:1080/favicon.ico", host: "forum.beginner.center", referrer: "http://forum.beginner.center/"
2024/04/17 11:39:00 [error] 353#353: *6712 connect() failed (111: Connection refused) while connecting to upstream, client: 58.153.170.44, server: forum.beginner.center, request: "GET / HTTP/2.0", upstream: "http://144.217.90.95:1080/", host: "forum.beginner.center"
2024/04/17 11:39:02 [error] 353#353: *6712 connect() failed (111: Connection refused) while connecting to upstream, client: 58.153.170.44, server: forum.beginner.center, request: "GET /service-worker.js HTTP/2.0", upstream: "http://144.217.90.95:1080/service-worker.js", host: "forum.beginner.center", referrer: "https://forum.beginner.center/service-worker.js"
2024/04/17 11:39:24 [error] 353#353: *6717 connect() failed (111: Connection refused) while connecting to upstream, client: 42.120.74.215, server: forum.beginner.center, request: "POST /message-bus/f6c7f114f96f40bfa1de74d4dee36743/poll?dlp=t HTTP/2.0", upstream: "http://144.217.90.95:1080/message-bus/f6c7f114f96f40bfa1de74d4dee36743/poll?dlp=t", host: "forum.beginner.center", referrer: "https://forum.beginner.center/t/topic/859"
2024/04/17 11:39:47 [error] 353#353: *6719 connect() failed (111: Connection refused) while connecting to upstream, client: 39.100.35.194, server: forum.beginner.center, request: "GET /posts.rss HTTP/1.1", upstream: "http://144.217.90.95:1080/posts.rss", host: "forum.beginner.center"

看日志信息中是上游服务器拒绝连接的意思。

就是反向代理访问了上游服务器,但是上游服务器没有给出返回数据,我感觉大概率是不是你的服务器上有防火墙,防火墙阻止了 1080 端口的访问?

目前已经开启了1080端口,查看端口占用也确实是docker在用

ubuntu@vps-7bd5d5fe:~$ sudo lsof -i:1080
COMMAND       PID USER   FD   TYPE    DEVICE SIZE/OFF NODE NAME
docker-pr 3407111 root    4u  IPv4 127562624      0t0  TCP *:socks (LISTEN)
docker-pr 3407116 root    4u  IPv6 127562627      0t0  TCP *:socks (LISTEN)
1 Like

我的意思是可能你的服务器的防火墙限制了 1080 端口的的访问。

你通过本地浏览器访问下 地址+端口能访问吗?

或者你在服务器上 CURL 下看看服务器能不能正确的提供数据输出。

curl确实无法访问1080

ubuntu@vps-7bd5d5fe:~$ curl 144.217.90.95:1080
curl: (7) Failed to connect to 144.217.90.95 port 1080 after 0 ms: Couldn't connect to server

防火墙已经开放1080

ubuntu@vps-7bd5d5fe:~$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
22                         ALLOW       Anywhere                  
443                        ALLOW       Anywhere                  
80                         ALLOW       Anywhere                  
587                        ALLOW       Anywhere                  
10593/tcp                  ALLOW       Anywhere                  
7500                       ALLOW       Anywhere                  
1201/tcp                   ALLOW       Anywhere                  
10587                      ALLOW       Anywhere                  
8080                       ALLOW       Anywhere                  
1080                       ALLOW       Anywhere                  
10443                      ALLOW       Anywhere                  
22 (v6)                    ALLOW       Anywhere (v6)             
443 (v6)                   ALLOW       Anywhere (v6)             
80 (v6)                    ALLOW       Anywhere (v6)             
587 (v6)                   ALLOW       Anywhere (v6)             
10593/tcp (v6)             ALLOW       Anywhere (v6)             
7500 (v6)                  ALLOW       Anywhere (v6)             
1201/tcp (v6)              ALLOW       Anywhere (v6)             
10587 (v6)                 ALLOW       Anywhere (v6)             
8080 (v6)                  ALLOW       Anywhere (v6)             
1080 (v6)                  ALLOW       Anywhere (v6)             
10443 (v6)                 ALLOW       Anywhere (v6)          

这样,先安全停止防火墙再访问下试试看?

同时,在服务器上自己访问自己,用:127.0.0.1 的这个地址看看能不能访问。

127.0.0.1可以curl,但是看起来数据都没了? :smiling_face_with_tear:
搞定以后我再从之前的备份恢复吧

ubuntu@vps-7bd5d5fe:/var/discourse$ curl 127.0.0.1 :1080
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>恭喜,站点创建成功!</title>
    <style>
        .container {
            width: 60%;
            margin: 10% auto 0;
            background-color: #f0f0f0;
            padding: 2% 5%;
            border-radius: 10px
        }

        ul {
            padding-left: 20px;
        }

        ul li {
            line-height: 2.3
        }

        a {
            color: #20a53a
        }
    </style>
</head>
<body>
<div class="container">
    <h1>恭喜, 站点创建成功!</h1>
    <h3>这是默认index.html,本页面由系统自动生成</h3>
    <ul>
        <li>您可以修改、删除或覆盖本页面</li>
    </ul>
</div>
</body>
</html>curl: (3) URL using bad/illegal format or missing URL

数据都没有了?

就算改变端口这个情况应该不会发生吧。

不知道你有没有做好足够的备份,在对服务器进行任何操作之前还是多需要备份才好,因为不知道什么情况下就会出现问题。

1 Like

哎。。。我去重装一下,然后恢复备份吧,不乱搞了😂

挺奇怪的。

就算修改端口,也不应该出现数据丢失的情况。

尤其是在生产服务器上,在没有完全备份的情况下,我们一般都不会主动对服务器进行调整。

就算要调整,也需要在另外一台机器上对调整的步骤进行测试后才可以。

1 Like

哎大意了,我以为端口调整很容易就能完成,没想到直接搞崩了,

现在app.yml恢复之前的配置(80、443端口、template),rebuild discoures,卸载了面板删除相关文件,重启了服务器,发现还是无法访问

ubuntu@vps-7bd5d5fe:/var/discourse$ curl 144.217.90.95:80
curl: (7) Failed to connect to 144.217.90.95 port 80 after 0 ms: Couldn't connect to server

但是防火墙应该没问题

ubuntu@vps-7bd5d5fe:/var/discourse$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
22                         ALLOW       Anywhere                  
443                        ALLOW       Anywhere                  
80                         ALLOW       Anywhere                  
587                        ALLOW       Anywhere                  
10593/tcp                  ALLOW       Anywhere                  
7500                       ALLOW       Anywhere                  
1201/tcp                   ALLOW       Anywhere                  
10587                      ALLOW       Anywhere                  
8080                       ALLOW       Anywhere                  
1080                       DENY        Anywhere                  
10443                      DENY        Anywhere                  
22 (v6)                    ALLOW       Anywhere (v6)             
443 (v6)                   ALLOW       Anywhere (v6)             
80 (v6)                    ALLOW       Anywhere (v6)             
587 (v6)                   ALLOW       Anywhere (v6)             
10593/tcp (v6)             ALLOW       Anywhere (v6)             
7500 (v6)                  ALLOW       Anywhere (v6)             
1201/tcp (v6)              ALLOW       Anywhere (v6)             
10587 (v6)                 ALLOW       Anywhere (v6)             
8080 (v6)                  ALLOW       Anywhere (v6)             
1080 (v6)                  DENY        Anywhere (v6)             
10443 (v6)                 DENY        Anywhere (v6) 

查看端口占用情况,也是docker在用

ubuntu@vps-7bd5d5fe:/var/discourse$ sudo lsof -i:80
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
docker-pr 10368 root    4u  IPv4  38636      0t0  TCP *:http (LISTEN)
docker-pr 10374 root    4u  IPv6  39496      0t0  TCP *:http (LISTEN)

ubuntu@vps-7bd5d5fe:/var/discourse$ sudo docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED         STATUS          PORTS                                                                      NAMES
091cbe151afb   local_discourse/app   "/sbin/boot"             8 minutes ago   Up 8 minutes    0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp   app
635bfdef820c   diygod/rsshub         "dumb-init -- npm ru…"   6 days ago      Up 24 minutes   0.0.0.0:1200->1200/tcp, :::1200->1200/tcp                                  rsshub-rsshub-1
efba7900095b   redis:alpine          "docker-entrypoint.s…"   6 days ago      Up 24 minutes   6379/tcp                                                                   rsshub-redis-1
72ba33edd467   browserless/chrome    "./start.sh"             6 days ago      Up 24 minutes   3000/tcp                                                                   rsshub-browserless-1

很奇怪不知道下一步要排查什么了

幸亏有之前传到s3的备份,实在不行就重装系统恢复吧

你先别使用服务器的地址 CURL,因为这个 CURL 会访问服务器。

你可以在服务器上 curl 127.0.0.1,这个是内部访问,先确定这个没有问题后在看看服务器是不是起来了。

curl 127.0.0.1也失败,这意味着网站并没有部署成功?

ubuntu@vps-7bd5d5fe:~$ curl 127.0.0.1:80
curl: (56) Recv failure: Connection reset by peer

如 127.0.0.1 也 Ping 不通的话,那有可能是服务器没有起来。

看到这个帖子,好像是nginx的问题,突然想起来,我之前折腾nginx的时候把nginx卸载了,所以访问不了,现在重装试试看

老大,请问你这个问题解决了么。

没有,现在一个主机专门开着80和443跑discourse,剩下的端口通过另一台主机反代域名访问

我用的1panel+discourse,端口默认是改好的

1 Like