Nov 24, 2011

Cloud Foundry and Custom Domain

Posted Nov 24, 2011
Currently, Cloud Foundry (CF) doesn't support mapping of external URL's (See discussion).  The workaround is to use a reverse proxy. For this job, I hosted it Google App Engine (GAE) and used BS2 GAE Reverse Proxy. Credits to yufeiwu for the free reverse proxy app.

Prerequisite:
- Also, please read the Python Tutorial for the development environment and pushing your app to Google server.

Steps:
  1. Download the reverse proxy library (license: LGPL) in http://code.google.com/p/bs2grproxy/
  2. Modify bs2grpconfig.py
    • set TARGET_HOST to your cloud foundry url
      e.g. TARGET_HOST = "mvergel.cloudfoundry.com"
  3. Modify app.yaml
    • set your registered application id
  4. Push the app and make it live

I will continue to use this approach for my website until CF have a proper DNS support.

[UPDATE] Many are encountering a problem with the session using this method. There is a patch that fixes this issue. Thank you Marius Anton for the information.

30 comments:

  1. Thanks for sharing this. I have used this to check DNS support but session variables are not maintaining across.. Can you give me some info on this?

    ReplyDelete
    Replies
    1. I have not tested this yet. I'll get back to you if I can replicate the problem. What framework are you using? I'm using Play Framework.

      Delete
  2. Hello Manny. I need your help. In your described way I can map "example.cloudfoundry.com" to "appid.appspot.com". But how can I map "example.cloudfoundry.com" to "example.com". I just can't figure out how did you do "mvergel.cloudfoundry.com" to "mvergel.com" mapping?

    ReplyDelete
    Replies
    1. mvergel.com is mapped to appid.appspot.com, appid.appspot.com is mapped to example.cloudfoundry.com. I used Google Apps (free) to map appspot to custom domain. Hope it helps

      Delete
  3. Thank you for your reply. One final clarification, please. You purchased mvergel.com domain and used Google Apps to map it to appspot, right?
    TIA.

    ReplyDelete
    Replies
    1. Yes, but to be exact.. I used Google Apps to purchase mvergel.com domain too, and mapped it to my appspot web application.

      Delete
    2. This comment has been removed by the author.

      Delete
    3. I make this work, but I'm having ERRORS with the URLs... can you help Me?

      Delete
    4. Sure! Could you be more specific on your problem?

      Delete
    5. in all the urls appear an jsessionid... so, the files are not found

      Delete
    6. I dont find any solution for this problem... can to help me?

      Delete
  4. Hi there... I tried to do the Mannys way to get my own URL to point to the cloudfoundry url... and I make it work. My problem is that ma webapp is putting the jsessionid in hte url so, all the links are broken when I enter throw the www.something.com url. can someone help me please!!!!

    Its very urgent!

    ReplyDelete
    Replies
    1. Can you give

      1. the exact URL having the problem?

      2. Also indicate your CloudFoundry URL

      3. The framework you are using.

      Delete
    2. Hi Manny, I have the servers down at this moment... the frameworks are spring+springSec+springMVC

      Delete
    3. I think I found the problem, is an encoding problem.... when I enter to the custom url www.some.com the Tomcat server on the cloud foundry generates the jsessionid variable on the url. Like this --> http://www.some.com/login.html;jsessionid=94B514CC3052E86CBB3492ADD0D33053

      But in the page you can see an error like this -->

      HTTP Status 404 - /login.html%3Bjsessionid%3D94B514CC3052E86CBB3492ADD0D33053

      type Status report

      message /login.html%3Bjsessionid%3D94B514CC3052E86CBB3492ADD0D33053

      description The requested resource (/login.html%3Bjsessionid%3D94B514CC3052E86CBB3492ADD0D33053) is not available.
      Apache Tomcat/6.0.35

      So, do you have any idea how is the ; and / changing on GAE proxy? how I change the encoding on the GAE?

      Delete
    4. I have replicated the problem in my server too. I'll try to look for a solution.

      Delete
    5. Please have a look at this patch http://code.google.com/p/bs2grproxy/issues/detail?id=13

      I had the same problem. The session id cookie (jsessionid if you are using jsp) was lost between requests, which resulted in creating a new session on cloudfoundry server. The above path solved this problem.

      Delete
    6. Thank you Marius! I have updated this post to reflect your suggestion.

      Delete
  5. Hi Manny,
    I followed your instructions, but when I try to enter to my home pages is redirected to www.google.com

    Could u please help me with that?

    thanks a lot!!!

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. add this to web.xml

    %3Csession-config%3E
    %3CCtracking-mode%3E
    COOKIE
    %3C/tracking-mode%3E
    %3C/session-config%3E

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. Can somebody tell me what this is meant to do? I have managed to setup the reverse proxy but am having the jsessionid issue - is this meant to fix the problem?

      Delete
    3. Please check the suggestion of Marius. I have also updated the blog entry above to link the fix relating to this issue.

      Delete
  8. this no longer works fine. my cloudfoundry app has spring+springMvc+springSecurity, and the proxy is mixing the sessions!!!

    ReplyDelete
    Replies
    1. Updated the blog entry to provide a link for the fix. Please check

      Delete
  9. I tried my own reverse proxy (with Apache and mod_proxy, hosted in an EC2 instance) to map a domain to an Grails app running at CF, but the result is NGix's page. I believe CF has blocked this workaround.

    ReplyDelete
    Replies
    1. mvergel.com uses this approach and it's still working. Hmm...

      Delete
  10. Hi . Can I know about the pricing issue ? I mean , how did you managed the "instance hour" thing on app engine ? Does page view on this site affect on GAE pricing ? If yes , then can you share some tips on how to optimize it ?

    Thanks in advance .

    ReplyDelete