You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker+Gunicorn部署的Django服务无法访问求助

Docker+Gunicorn部署的Django服务无法访问求助

大家好,我在RHEL服务器上用Docker部署了一个Django应用,搭配Gunicorn做WSGI服务器,结果遇到了访问超时的问题,折腾好一阵没搞定,来求助各位大佬!

具体情况是:当我在浏览器访问服务器的10.xxx.xx.xx地址时,一直收到提示:

This site can’t be reached 10.xxx.xx.xx took too long to respond.
Try:
Checking the connection
Checking the proxy and the firewall
Running Windows Network Diagnostics

下面是我的相关配置和排查情况:

一、相关配置文件

1. 容器启动脚本 entrypoint.sh

这是Docker容器启动时执行的脚本,用来启动Gunicorn:

exec gunicorn --bind 0.0.0.0:${PORT:-8000} --timeout 300 -w 4 -t 4 wtools2.wsgi:application

2. Docker Compose 配置

version: '3.8'

services:
  web:
    build:
      context: .
      dockerfile: Dockerfile
    command: /code/entrypoint.sh
    volumes:
      - ./wtools2:/code/wtools2
    ports:
      - "${PORT:-8000}:8000"
    environment:
      - DJANGO_SETTINGS_MODULE=wtools2.settings_production
      - PYTHONPATH=/code/
      - DJANGO_ENV=production

3. 服务器端口监听状态

我在RHEL服务器上执行了netstat -tuln命令,得到的结果如下:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN
tcp        0      0 xx.xx.xx.xx:8000        0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN
tcp        0      0 xx.xx.xx.xx:5000        0.0.0.0:*               LISTEN

二、已经排查的事项

  • 联系了公司的网络工程师,对方确认**"the communication flow is allowed from network side, no restriction for whole subnet"**,网络层面没有针对这个子网的访问限制
  • 确认容器处于正常运行状态(docker ps显示容器状态为Up)
  • 核对过端口映射:Docker Compose里把主机的${PORT:-8000}端口映射到容器的8000端口,和Gunicorn绑定的端口一致

有没有大佬能帮忙分析下可能的问题?比如是不是Gunicorn的绑定配置有隐藏问题?或者Docker的网络模式有没有需要调整的地方?还有哪些排查方向可以尝试呢?

备注:内容来源于stack exchange,提问作者Usman Rafiq

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 11:59:34