title: Issue with AWS Elastic Load Balancing sticky sessions - subdomains are being served from different servers?
body: <p>I'm quite new to load balancing and I'm having some problems with getting Amazon's Elastic Load Balancer to play nice with subdomains.  </p>
  
  <p>I have two EC2 servers behind my load balancer.  When I go to <em>mydomain.com</em> and <em>www.mydomain.com</em>, the two urls are served from different EC2 servers.  I need both <em>www.mydomain.com</em> and <em>mydomain.com</em> to be served from the same server so that sessions work properly.</p>
  
  <p>I have the load balancer "stickyness" set to LBCookieStickinessPolicy like so:</p>
  
  <p><img src="https://i.stack.imgur.com/IMDju.png" alt="enter image description here"></p>
  
  <p>And my two EC2 instances are both "In Service" behind my load balancer:</p>
  
  <p><img src="https://i.stack.imgur.com/aLRZC.png" alt="enter image description here"></p>
  
  <p>I don't know if it's useful for troubleshooting, but my apache configuration looks like:</p>
  
  <p><img src="https://i.stack.imgur.com/VJioY.png" alt="enter image description here"></p>
  
  <p>When I view the sessions in Firebug, I see the following...</p>
  
  <p>For mydomain.com:</p>
  
  <p><img src="https://i.stack.imgur.com/JuOZm.png" alt="enter image description here"></p>
  
  <p>For www.mydomain.com (notice the additional "www.")</p>
  
  <p><img src="https://i.stack.imgur.com/TQ92Q.png" alt="enter image description here"></p>
  
  <p>I'm not sure why, but there are actually two AWSELB cookies set when viewing the cookies for www.mydomain.com.</p>
  
  <p>I'm using the Zend Framework, and I'm setting my cookie_domain like so:</p>
  
  <pre><code>Zend_Session::start(array('cookie_domain' =&gt; '.mydomain.com'));
  </code></pre>
  
  <p>This has worked fine in the past before moving the site to the two load balanced EC2 servers.  Our site uses a few subdomains, such as api.mydomain.com and my.mydomain.com, which made the cookie_domain important.  And, granted, this might be OK.  It's quite possible that once we get the load balancer session "sticky" to work properly between subdomains, session variables will work as expected (hopefully!).</p>
  
  <p>Any ideas why our site is being served from different servers when the "www." is added to the domain name?</p>
  
  <p>Thanks!</p>