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.comornslookup subdomain.domain.comin 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, notlocalhost: If your app is only listening onlocalhost, it'll respond to requests from the EC2 instance itself but not from the Load Balancer. Update yourapp.listen()call to:app.listen(3000, '0.0.0.0', () => { console.log('Server running on port 3000'); }); - CORS Restrictions: If your
config/config.jsincludes CORS settings, make suresubdomain.domain.comis added to the allowed origins. For example, if you're using thecorspackage, your config might look like:
Temporarily disable CORS to test if that's the blockage.const corsOptions = { origin: ['https://subdomain.domain.com', 'https://your-loadbalancer-url'], credentials: true };
4. Test with Detailed Debugging
- Use
curl -v https://subdomain.domain.comto 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
相关产品推荐
相关产品推荐

