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

CentOS7下Apache结合Gunicorn部署Django后访问失败如何解决

排查步骤

  • 先验证Gunicorn本身可正常访问
    在服务器本地执行 curl 127.0.0.1:8000,如果返回Django页面内容说明Gunicorn启动正常;如果提示连接拒绝,先执行 netstat -tunlp | grep 8000 确认Gunicorn是否正常监听8000端口,推荐启动命令为 gunicorn --bind 127.0.0.1:8000 testproject.wsgi:application,启动前要确保处于项目根目录、已经激活了虚拟环境。
  • 检查Apache必需模块是否启用
    反向代理依赖mod_proxy和mod_proxy_http两个模块,执行 httpd -M | grep proxy 查看是否已经加载,未加载的话执行以下命令启用后重启httpd:
    yum install mod_proxy_http
    systemctl restart httpd
    
    你当前Apache配置里的<Directory /home/user/django_test/testproject>相关的<Files wsgi.py>配置是mod_wsgi模式下才需要的,反向代理模式下可以删除,不影响功能。
  • 验证端口与防火墙配置
    执行 netstat -tunlp | grep httpd 确认httpd服务正常监听80端口,再执行 firewall-cmd --list-all 检查firewalld是否开放了80端口的公网访问权限,未开放的话执行:
    firewall-cmd --add-service=http --permanent
    firewall-cmd --reload
    
    如果服务器有云服务商的安全组,也要确认安全组放行80端口的入站规则。
  • 验证域名解析
    在你本地电脑上执行 ping 你的域名,确认返回的IP地址和你服务器的公网IP完全一致。
  • 检查目录权限
    Apache运行用户默认是apache,需要有项目目录的读权限,执行 chmod -R 755 /home/user/django_test 赋予目录最低必要权限。
  • 检查Apache配置语法
    每次修改配置后执行 httpd -t 验证语法是否正确,提示Syntax OK再执行 systemctl restart httpd 重启服务生效。

如果以上步骤都排查完还是无法访问,查看Apache错误日志定位具体问题,日志默认路径为/var/log/httpd/error_log。

内容的提问来源于stack exchange,提问作者bgood201

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.01 08:36:04