我正在使用moodle-docker并试图在云VPS(虚拟专用服务器)上运行它,我已经购买了一个域名并将其链接到VPS提供的公共ip地址。
我已经在VPS中克隆了一个Moodle存储库,并设置了Moodle -docker来指向它,像这样
export MOODLE_DOCKER_WWWROOT=~/Sources/moodle &&
export MOODLE_DOCKER_DB=mysql &&
export MOODLE_DOCKER_WEB_HOST=my-domain.my.id &&
export MOODLE_DOCKER_WEB_PORT=8000
,但当我打开my-domain.my.id:8000
它给我错误Connection refused
。我也尝试使用curl
,甚至从VPS内部本身,这里是命令:
curl -v -g 'http://my-domain.my.id:8000'
结果:
* Trying 103.170.85.180:8000...
* TCP_NODELAY set
* connect to 103.170.85.180 port 8000 failed: Connection refused
* Failed to connect to my-domain.my.id port 8000: Connection refused
* Closing connection 0
curl: (7) Failed to connect to my-domain.my.id port 8000: Connection refused
我还尝试在它上运行一个自定义web服务器,以确保我可以从互联网访问它。web服务器运行在端口8085上,我可以curl
它很好:
curl -v -g 'http://my-domain.my.id:8085/ping'
* Trying 103.170.85.180:8085...
* TCP_NODELAY set
* Connected to my-domain.my.id (103.170.85.180) port 8085 (#0)
> GET /ping HTTP/1.1
> Host: my-domain.my.id:8085
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< X-Powered-By: Express
< Access-Control-Allow-Origin: *
< Content-Type: application/json; charset=utf-8
< Content-Length: 54
< ETag: W/"36-wY0ccM5thB7kDQk7rQPWw2Kfc/Y"
< Date: Mon, 11 Jul 2022 03:45:35 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
<
* Connection #0 to host my-domain.my.id left intact
{"status":"running","time":"2022-07-11T03:45:35.204Z"}
我已经修修补补了几天没有结果,所以如果你有任何我可以尝试的,请随时评论
检查运行docker的列表我注意到web服务器上可以访问的端口使用0.0.0.0:8085->8085/tcp
和moodle-docker使用127.0.0.1:8000->80/tcp
。我读了moodle-docker-compose,如果没有指定绑定ip,它使用127.0.0.1
。
所以从
export MOODLE_DOCKER_WEB_PORT=8000
export MOODLE_DOCKER_WEB_PORT=0.0.0.0:8000
对我有用,但我不知道为什么。有人能解释一下原因吗?