title: CloudFront - Serve static website from S3, route API requests to EC2 on custom port
body: <p>I have a similar setup as this <a href="https://stackoverflow.com/questions/32360255/how-to-serve-static-media-contents-only-from-s3-and-others-from-ec2?rq=1">question</a>. </p>
  
  <p>I have set up CloudFront as a CDN. In CloudFront I created two origins:</p>
  
  <ul>
  <li>The S3 Bucket serving static contents (works fine)</li>
  <li>The EC2 machine with some API server running on port 8888</li>
  </ul>
  
  <p>Now in CloudFront I have added one behavior (<code>precedence 0</code>) that all requests to "<code>/api/*</code>" are forwarded to the EC2 instance, including all header and whatsoever. The whole thing should be serving via HTTPS (S3 and EC2).</p>
  
  <p>The problem is that requests to /api seem to time-out. I'm not sure where the problem is. Maybe it is related to:</p>
  
  <ul>
  <li>The port - where can/should I reflect that the port number is <code>8888</code>? I have also tried to define the HTTPS port in the origin settings as "<code>8888</code>" instead of "<code>443</code>"</li>
  <li>Some other security or mapping settings?</li>
  </ul>
  
  <p><strong>Note</strong>: I have not yet updated the DNS settings, that CloudFront points to the real domain. Currently using the domain generated by CloudFront only.</p>