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

EC2实例Elastic IP可访问Django站点,Route53域名访问显示Nginx首页问题

问题原因与解决方法

问题出在Nginx配置的server_name仅设置了Elastic IP,当用域名访问时,Nginx找不到匹配该域名的server块,就会自动使用默认的server配置(也就是显示默认首页的那个)。

解决步骤:

  • 编辑你的Nginx站点配置文件(通常在/etc/nginx/sites-available/目录下,或/etc/nginx/nginx.conf内的server块),把server_name替换为你的域名,若需支持www前缀也一并加上:
    server {
    listen 80;
    # 替换成你的实际域名
    server_name yourdomain.com www.yourdomain.com;
    
    location = /favicon.ico { access_log off; log_not_found off; }
    
    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }}
    
  • 检查Nginx配置是否合法:
    sudo nginx -t
    
  • 若提示test is successful,重启Nginx使配置生效:
    sudo systemctl restart nginx
    
  • 额外确认:确保Route53的A记录已正确指向你的Elastic IP,可通过ping yourdomain.com检查返回的IP是否与Elastic IP一致。

内容的提问来源于stack exchange,提问作者Hemant Kumar Chaudhary

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 14:01:35