When your naked domain (example.com
) works but the www subdomain (www.example.com
) fails with HTTP 502, this typically indicates DNS configuration issues. The ping failure confirms the www
hostname isn't resolving to any IP address.
There are three primary ways to configure www:
1. A Record (Direct IP mapping):
www.example.com. IN A 192.0.2.1
2. CNAME (Alias to main domain):
www.example.com. IN CNAME example.com.
3. ALIAS/ANAME (Special record type):
www.example.com. IN ALIAS example.com.
Here's how to implement solution #2 (CNAME approach) in common hosting panels:
Cloudflare Example
1. Navigate to DNS → Records
2. Add Record:
- Type: CNAME
- Name: www
- Target: example.com
- TTL: Auto
3. Enable "Proxy status" if using Cloudflare CDN
AWS Route 53 Example
{
"Changes": [{
"Action": "CREATE",
"ResourceRecordSet": {
"Name": "www.example.com",
"Type": "CNAME",
"TTL": 300,
"ResourceRecords": [{
"Value": "example.com"
}]
}
}]
}
For Apache servers, ensure your .htaccess
or vhost config includes:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html
# Other directives...
</VirtualHost>
Use these diagnostic commands:
# Check DNS resolution
dig www.example.com +short
# Verify HTTP response
curl -I http://www.example.com
# Test SSL (if applicable)
openssl s_client -connect www.example.com:443 -servername www.example.com | openssl x509 -noout -dates
- DNS propagation delays (up to 48 hours)
- CNAME at root domain (technically invalid)
- Missing ServerAlias in web server config
- Cloudflare proxy status mismatches
The core issue stems from incomplete DNS configuration. While your apex domain (example.com
) has proper A/AAAA records pointing to your server, the www
subdomain lacks these crucial records.
// DNS architecture example
example.com. IN A 192.0.2.1
www.example.com. IN CNAME example.com. // Missing in your case
The www
prefix is technically a subdomain that needs explicit configuration. Modern web standards treat them as separate entities in DNS resolution.
Option 1: Create CNAME Record (Recommended)
Most registrars/hosting providers allow DNS management through their control panel:
1. Log in to your DNS provider
2. Locate DNS management section
3. Add new record:
- Type: CNAME
- Name: www
- Value: example.com
- TTL: 3600 (or default)
Option 2: Duplicate A Record
For bare metal servers or specific configurations:
www.example.com. IN A 192.0.2.1 // Same IP as apex domain
After making changes, verify using these terminal commands:
dig www.example.com +short // Should return your server IP
curl -I http://www.example.com // Check HTTP status code
If DNS is correct but still getting 502:
- Check virtual host configuration (Nginx/Apache example):
# Nginx server block example
server {
listen 80;
server_name www.example.com example.com;
# Rest of configuration...
}
- 0-5 min: DNS changes made
- 5-30 min: Propagation begins (check with
dig
) - 30+ min: Full global propagation