How to make an application be accessed as a sub path of a main application

62 views
Skip to first unread message

meteo...@gmail.com

unread,
Apr 15, 2015, 5:01:59 AM4/15/15
to vcap...@cloudfoundry.org
Hello, all

I am using CF v1, and we had some requirement like this:
we had several apps and their URLs like


We want to make them protected by wildcard "*.abc.com", but "admin.prefix1.abc.com" is not in that case.

An alternative approach we think is, we can proxy request to backend application like this


Is it doable?

I tried to add location /admin like below, but it always make the CF components failed to communicate with cloud controller, any suggestion?


server {
    # use chunkin-http
    chunkin on;
    error_page 411 = @my_411_error;
    location @my_411_error {
      chunkin_resume;
    }
    # end of http-chunkin

    listen       80;
    client_max_body_size 1024M;
    server_name  _;
    server_name_in_redirect off;

    #TODO: how to make this internal location totally transparent to outside
    location = /vcapuls {
      internal;
      # We should use rewrite_by_lua to scrub subrequest headers
      # as uls doesn't care those headers at all.
      # Given there are some exceptions to clear some headers,
      # we just leave them as is.

      keepalive_requests 200;
      proxy_pass http://127.0.0.1:8081/;
      # Don't use unix sockets.
      #proxy_pass http://unix:/tmp/router.sock:/;
    }
    location /nginx {
        autoindex    on;
        root   /var/www;
        expires     max;
    }
    # Make sure there is a /var/www/nginx/404/404.html page
    error_page  404 /nginx/404/404.html;

    location /admin {
    
    }

    location / {
      access_log   /home/ubuntu/cloudfoundry/.deployments/intalio_devbox/log/nginx/nginx_router_access.log main;
      proxy_buffering             off;
      proxy_set_header            Host $host;
      proxy_set_header            X-Real_IP $remote_addr;
      proxy_set_header            X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header            X-Forwarded-Proto http;
      proxy_redirect              off;
      proxy_connect_timeout       40;
      proxy_send_timeout          480;
      proxy_read_timeout          480;

      set $health_monitor '';
      set $app_id 0;
      if ($http_user_agent = "HTTP-Monitor/1.1") {
        set $health_monitor T;
      }
      if ($http_host = "") {
        set $health_monitor "${health_monitor}T";
      }
      if ($health_monitor = TT) {
        # Trigger a subrequest to sync the latest few stats of the worker to uls,
        # if we have multiple workers, there will be still few stats not synced for
        # the workers which don't get this monitor request.
        access_by_lua '
          local uls = require ("uls")

          ngx.log(ngx.DEBUG, "monitor trigger stats syncup")

          local req = uls.generate_stats_request()

          -- generate one subrequest to uls to update stats
          ngx.location.capture(
            "/vcapuls", { body = req }
          )
        ';

        more_set_input_headers "Authorization: Basic YWRtaW46cGFzc3dvcmQ=";
        rewrite ^.*$ /healthz break;
        proxy_pass                 http://router_status;
      }

      # We intend to have one "if" block to avoid the above monitor location
      # to twist with below upstream locator server handling.
      # ("if" block effectively creates a nested location and will inherit
      # all the rewrite/access phase handlers of outer location)
      if ($health_monitor != TT) {
        # The following variables are used by lua module code.
        # DO NOT remove or rename any of them!
        set $backend_addr ''; # Backend server address returned from uls for this request
        set $uls_req_tags ''; # Request tags returned from uls for this request to catalog statistics
        set $router_ip '';
        set $timestamp 0;
        set $trace '';
        set $sticky '';

        access_by_lua '
          local uls = require ("uls")

          uls.pre_process_subrequest(ngx, "222")

          local req = uls.generate_uls_request(ngx)

          -- generate one subrequest to uls for querying
          local res = ngx.location.capture(
            "/vcapuls", { body = req }
          )

          uls.post_process_subrequest(ngx, res)
        ';

        proxy_pass http://$backend_addr;

        # Handling response from backend servers
        header_filter_by_lua '
          local uls = require ("uls")

          uls.post_process_response(ngx)
        ';
      }
    }

meteorping

unread,
Apr 16, 2015, 1:21:55 PM4/16/15
to vcap...@cloudfoundry.org
In simple word, I just want to the sub domain application as a sub path of the main application.

abc.com which is the main application.

sub domain as a sub path

I want to do it in nginx router.

Any suggestion how to do it?

James Bayer

unread,
Apr 17, 2015, 12:02:37 AM4/17/15
to vcap...@cloudfoundry.org
since the router doesn't support context path based routing yet, you could have app1 resolve to abc.com and essentially be a proxy. you can write a simple java app to do that with rewrite rules. v1 didn't have buildpacks, so it's not as easy to use something like the https://github.com/cloudfoundry-incubator/staticfile-buildpack

have app2 be admin.abc.com

in app1 rewrite all requests to abc.com/admin and to admin.abc.com and forward


except you don't need the 2nd private load balancer

--
You received this message because you are subscribed to the Google Groups "Cloud Foundry Developers" group.
To view this discussion on the web visit https://groups.google.com/a/cloudfoundry.org/d/msgid/vcap-dev/e86e66fd-d819-47dd-8f5d-9b1ff1e3a271%40cloudfoundry.org.

To unsubscribe from this group and stop receiving emails from it, send an email to vcap-dev+u...@cloudfoundry.org.



--
Thank you,

James Bayer
Reply all
Reply to author
Forward
0 new messages