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

Node.js Express应用AWS Route53子域名指向LoadBalancer失效问题

Troubleshooting Route53 Subdomain Issues with AWS Load Balancer & Node.js/Express

Hey there, let's walk through the most common fixes for your subdomain access problem. You mentioned the Load Balancer URL works fine, so the issue is almost certainly in the Route53 setup, Load Balancer config, or a small oversight in your Express app.

1. Verify Route53 Alias Record Setup First

This is the most frequent culprit:

  • Double-check the alias target: Make sure you selected the correct Load Balancer in the same AWS region when creating the alias. Alias records only work with AWS resources in the same region, and you must choose an A/AAAA record type (not CNAME) for the alias to function properly.
  • Confirm DNS propagation: Even though Route53 propagates fast, run dig subdomain.domain.com or nslookup subdomain.domain.com in your terminal to check if the subdomain resolves to your Load Balancer's domain. If it doesn't, wait a few minutes or recheck your record setup.

2. Audit Load Balancer Configuration

  • Security Group Rules: Ensure your Load Balancer's security group allows inbound traffic on the port you're using (80 for HTTP, 443 for HTTPS) from 0.0.0.0/0 (or your desired IP range). If the security group blocks internet traffic, even correct DNS won't help.
  • Listener & Target Group Settings: Verify your Load Balancer's listener is forwarding traffic to the right port on your EC2 instances (e.g., if your Express app runs on port 3000, the listener should map 80 → 3000). Also, check that your target group's health checks are passing—if health checks fail, the Load Balancer won't send traffic to your instances. Set the health check path to / (since your root endpoint returns 200) and match the correct port/protocol.

3. Check Your Express App Configuration

  • Bind to 0.0.0.0, not localhost: If your app is only listening on localhost, it'll respond to requests from the EC2 instance itself but not from the Load Balancer. Update your app.listen() call to:
    app.listen(3000, '0.0.0.0', () => {
      console.log('Server running on port 3000');
    });
    
  • CORS Restrictions: If your config/config.js includes CORS settings, make sure subdomain.domain.com is added to the allowed origins. For example, if you're using the cors package, your config might look like:
    const corsOptions = {
      origin: ['https://subdomain.domain.com', 'https://your-loadbalancer-url'],
      credentials: true
    };
    
    Temporarily disable CORS to test if that's the blockage.

4. Test with Detailed Debugging

  • Use curl -v https://subdomain.domain.com to get verbose request/response details. This will tell you if the DNS resolves, if the connection times out, or if you're getting an unexpected status code (like 403/500).
  • Check your app's logs (via Forever or your logging setup) to see if requests from the Load Balancer are even reaching the app. If no logs show up, the issue is upstream (Route53/LoadBalancer). If logs show errors, debug the app's response logic.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 06:22:55