First, you should be sure that you can resolve www.example.com. When you ping www.example.com, does it resolve the same IP address as example.com?
If the resolve for both are to the same address, the issue is more than likely host header related. If you are running IIS, open IIS Manager and expand your sites. Right click the site for example.com and select "Edit Bindings". Locate the entry that is resolving on port 80 and edit the entry. If the "Host Name" is empty, type in www.example.com and save the settings.
If the host name is not empty, select to add another entry. Type in port 80 for the port and enter in the hostname www.example.com.
If you are running Apache, check your apache configuration for the host. It should look something like the below example. ServerAlias would be the important part to add to your configuration.
<VirtualHost *:80>
DocumentRoot /var/www/example.com/
ServerName example.com
ServerAlias www.example.com
<Directory "/var/www/example.com/">
allow from all
Options None
Require all granted
</Directory>
</VirtualHost>