{"action":"created","issue":{"url":"https://api.github.com/repos/lonelycode/tyk/issues/59","labels_url":"https://api.github.com/repos/lonelycode/tyk/issues/59/labels{/name}","comments_url":"https://api.github.com/repos/lonelycode/tyk/issues/59/comments","events_url":"https://api.github.com/repos/lonelycode/tyk/issues/59/events","html_url":"https://github.com/lonelycode/tyk/issues/59","id":74099479,"number":59,"title":"Setup for Multi-Tenant Micro-services","user":{"login":"DavidTPate","id":2223120,"avatar_url":"https://avatars.githubusercontent.com/u/2223120?v=3","gravatar_id":"","url":"https://api.github.com/users/DavidTPate","html_url":"https://github.com/DavidTPate","followers_url":"https://api.github.com/users/DavidTPate/followers","following_url":"https://api.github.com/users/DavidTPate/following{/other_user}","gists_url":"https://api.github.com/users/DavidTPate/gists{/gist_id}","starred_url":"https://api.github.com/users/DavidTPate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DavidTPate/subscriptions","organizations_url":"https://api.github.com/users/DavidTPate/orgs","repos_url":"https://api.github.com/users/DavidTPate/repos","events_url":"https://api.github.com/users/DavidTPate/events{/privacy}","received_events_url":"https://api.github.com/users/DavidTPate/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2015-05-07T19:28:55Z","updated_at":"2015-05-14T19:55:34Z","closed_at":"2015-05-08T00:16:21Z","body":"Hi there! I'm trying out Tyk and running into an issue with translating requests to be able to support a multi-tenant micro-service based architecture. Hoping to understand if there is some way that Tyk would be able to support my use case or if it is something that could be enhanced within Tyk to support it.\r\n\r\nIn my case I'm setup like this:\r\n\r\nAPI consumer makes a request to `https://{client}.mydomain.com/{service}/{path}` where `{client}` is a client name and `{service}` is the particular micro-service that they are attempting to access and `{path}` is everything after the name of the micro-service. Once this request is processed by Tyk it is sent to `https://{service}.myinternaldomain.com/{path}` but I need to provide the `{client}` value to my target somehow.\r\n\r\nThe simplest way that I can think of to approach this is to simply forward my original `Host` header, but I', not seeing how this could be done with Tyk right now.\r\n\r\nThe next would be to be able to dynamically rewrite the URL. In this case I would have Tyk rewrite `https://{client}.mydomain.com/{service}/{path}` (where `{client}` and `{path}` are both dynamic values) into something along the lines of `https://{service}.myinternaldomain.com/clients/{client}/{path}` but I'm not seeing a clear path as to how I would accomplish this with Tyk right now either.\r\n\r\nThose are the options which are clear to me right now, I'd love to hear your opinions or if there is some way that Tyk would support something like this but I am just missing it.\r\n\r\nThanks!"},"comment":{"url":"https://api.github.com/repos/lonelycode/tyk/issues/comments/102150121","html_url":"https://github.com/lonelycode/tyk/issues/59#issuecomment-102150121","issue_url":"https://api.github.com/repos/lonelycode/tyk/issues/59","id":102150121,"user":{"login":"DavidTPate","id":2223120,"avatar_url":"https://avatars.githubusercontent.com/u/2223120?v=3","gravatar_id":"","url":"https://api.github.com/users/DavidTPate","html_url":"https://github.com/DavidTPate","followers_url":"https://api.github.com/users/DavidTPate/followers","following_url":"https://api.github.com/users/DavidTPate/following{/other_user}","gists_url":"https://api.github.com/users/DavidTPate/gists{/gist_id}","starred_url":"https://api.github.com/users/DavidTPate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DavidTPate/subscriptions","organizations_url":"https://api.github.com/users/DavidTPate/orgs","repos_url":"https://api.github.com/users/DavidTPate/repos","events_url":"https://api.github.com/users/DavidTPate/events{/privacy}","received_events_url":"https://api.github.com/users/DavidTPate/received_events","type":"User","site_admin":false},"created_at":"2015-05-14T19:55:34Z","updated_at":"2015-05-14T19:55:34Z","body":"Yeah, my hosts file is setup correctly. No worries, sometimes it's the easiest stuff to miss.\r\n\r\n```\r\n192.168.1.xxx     www.localhost.com\r\n192.168.1.xxx     test.localhost.com\r\n192.168.1.xxx     httpbin.www.localhost.com\r\n192.168.1.xxx     google.www.localhost.com\r\n192.168.1.xxx     httpbin.test.localhost.com\r\n192.168.1.xxx     google.test.localhost.com\r\n```\r\n\r\nHere's what the files look like:\r\n\r\n**5fb3afce708c443e6046804aad2bb564.tconf**\r\n```\r\nserver {\r\n    \r\n    server_name httpbin.www.tyk.docker;\r\n\r\n    gzip              on;\r\n    gzip_buffers      16 8k;\r\n    gzip_comp_level   4;\r\n    gzip_http_version 1.1;\r\n    gzip_min_length   1280;\r\n    gzip_types        text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp;\r\n    gzip_vary         on;\r\n\r\n    # The Go application server\r\n    location / {\r\n        rewrite /(.*) /5fb3afce708c443e6046804aad2bb564/$1 break;\r\n\r\n        proxy_pass_header Server;\r\n        proxy_set_header Host $http_host;\r\n        proxy_redirect off;\r\n        proxy_set_header X-Real-IP $remote_addr;\r\n        proxy_set_header X-Scheme $scheme;\r\n        proxy_pass http://tyk;\r\n    }\r\n}\r\n```\r\n\r\n**6582f6f6419243786f5871bb83184acb.tconf**\r\n```\r\nserver {\r\n    \r\n    server_name google.www.tyk.docker;\r\n\r\n    gzip              on;\r\n    gzip_buffers      16 8k;\r\n    gzip_comp_level   4;\r\n    gzip_http_version 1.1;\r\n    gzip_min_length   1280;\r\n    gzip_types        text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp;\r\n    gzip_vary         on;\r\n\r\n    # The Go application server\r\n    location / {\r\n        rewrite /(.*) /6582f6f6419243786f5871bb83184acb/$1 break;\r\n\r\n        proxy_pass_header Server;\r\n        proxy_set_header Host $http_host;\r\n        proxy_redirect off;\r\n        proxy_set_header X-Real-IP $remote_addr;\r\n        proxy_set_header X-Scheme $scheme;\r\n        proxy_pass http://tyk;\r\n    }\r\n}\r\n```\r\n\r\n**bbd1f881d3d14ada6c02fd56d2d39c4b.tconf**\r\n```\r\nserver {\r\n    \r\n    server_name httpbin.test.tyk.docker;\r\n\r\n    gzip              on;\r\n    gzip_buffers      16 8k;\r\n    gzip_comp_level   4;\r\n    gzip_http_version 1.1;\r\n    gzip_min_length   1280;\r\n    gzip_types        text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp;\r\n    gzip_vary         on;\r\n\r\n    # The Go application server\r\n    location / {\r\n        rewrite /(.*) /bbd1f881d3d14ada6c02fd56d2d39c4b/$1 break;\r\n\r\n        proxy_pass_header Server;\r\n        proxy_set_header Host $http_host;\r\n        proxy_redirect off;\r\n        proxy_set_header X-Real-IP $remote_addr;\r\n        proxy_set_header X-Scheme $scheme;\r\n        proxy_pass http://tyk;\r\n    }\r\n}\r\n```\r\n\r\n**e415d7cd4546498873370868295a70b0.tconf**\r\n```\r\nserver {\r\n    \r\n    server_name google.test.tyk.docker;\r\n\r\n    gzip              on;\r\n    gzip_buffers      16 8k;\r\n    gzip_comp_level   4;\r\n    gzip_http_version 1.1;\r\n    gzip_min_length   1280;\r\n    gzip_types        text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp;\r\n    gzip_vary         on;\r\n\r\n    # The Go application server\r\n    location / {\r\n        rewrite /(.*) /e415d7cd4546498873370868295a70b0/$1 break;\r\n\r\n        proxy_pass_header Server;\r\n        proxy_set_header Host $http_host;\r\n        proxy_redirect off;\r\n        proxy_set_header X-Real-IP $remote_addr;\r\n        proxy_set_header X-Scheme $scheme;\r\n        proxy_pass http://tyk;\r\n    }\r\n}\r\n```\r\n\r\n**test.admin.portal.tconf**\r\n```\r\nserver {\r\n        \r\n        server_name test.tyk.docker;\r\n\r\n        gzip              on;\r\n        gzip_buffers      16 8k;\r\n        gzip_comp_level   4;\r\n        gzip_http_version 1.1;\r\n        gzip_min_length   1280;\r\n        gzip_types        text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp;\r\n        gzip_vary         on;\r\n\r\n        # The Go application server\r\n        location /portal/ {\r\n            rewrite /portal/(.*) /5554fa4019406a0001000003/portal/$1 break;\r\n\r\n            proxy_pass_header Server;\r\n            proxy_set_header Host $http_host;\r\n            proxy_redirect off;\r\n            proxy_set_header X-Real-IP $remote_addr;\r\n            proxy_set_header X-Scheme $scheme;\r\n            proxy_pass http://dashboard;\r\n        }\r\n        location /portal-assets/ {\r\n            proxy_pass_header Server;\r\n            proxy_set_header Host $http_host;\r\n            proxy_redirect off;\r\n            proxy_set_header X-Real-IP $remote_addr;\r\n            proxy_set_header X-Scheme $scheme;\r\n            proxy_pass http://dashboard;\r\n        }\r\n        location /api/public {\r\n            proxy_pass_header Server;\r\n            proxy_set_header Host $http_host;\r\n            proxy_redirect off;\r\n            proxy_set_header X-Real-IP $remote_addr;\r\n            proxy_set_header X-Scheme $scheme;\r\n            proxy_pass http://dashboard;\r\n        }\r\n}\r\n```\r\n\r\n**www.admin.portal.tconf**\r\n```\r\nserver {\r\n        \r\n        server_name www.tyk.docker;\r\n\r\n        gzip              on;\r\n        gzip_buffers      16 8k;\r\n        gzip_comp_level   4;\r\n        gzip_http_version 1.1;\r\n        gzip_min_length   1280;\r\n        gzip_types        text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp;\r\n        gzip_vary         on;\r\n\r\n        # The Go application server\r\n        location /portal/ {\r\n            rewrite /portal/(.*) /5554fa4019406a0001000002/portal/$1 break;\r\n\r\n            proxy_pass_header Server;\r\n            proxy_set_header Host $http_host;\r\n            proxy_redirect off;\r\n            proxy_set_header X-Real-IP $remote_addr;\r\n            proxy_set_header X-Scheme $scheme;\r\n            proxy_pass http://dashboard;\r\n        }\r\n        location /portal-assets/ {\r\n            proxy_pass_header Server;\r\n            proxy_set_header Host $http_host;\r\n            proxy_redirect off;\r\n            proxy_set_header X-Real-IP $remote_addr;\r\n            proxy_set_header X-Scheme $scheme;\r\n            proxy_pass http://dashboard;\r\n        }\r\n        location /api/public {\r\n            proxy_pass_header Server;\r\n            proxy_set_header Host $http_host;\r\n            proxy_redirect off;\r\n            proxy_set_header X-Real-IP $remote_addr;\r\n            proxy_set_header X-Scheme $scheme;\r\n            proxy_pass http://dashboard;\r\n        }\r\n}\r\n```\r\n\r\nI went through and pulled up the APIs to make sure that the organizations and the API IDs matched. Everything looked fine:\r\n\r\n**Organizations**\r\n```js\r\n{\r\n  \"organisations\": [\r\n    {\r\n      \"id\": \"5554fa4019406a0001000002\",\r\n      \"owner_name\": \"WWW\",\r\n      \"owner_slug\": \"www\",\r\n      \"apis\": [\r\n        {\r\n          \"api_human_name\": \"HttpBin\",\r\n          \"api_id\": \"5fb3afce708c443e6046804aad2bb564\"\r\n        },\r\n        {\r\n          \"api_human_name\": \"Google\",\r\n          \"api_id\": \"6582f6f6419243786f5871bb83184acb\"\r\n        }\r\n      ],\r\n      \"developer_quota\": 0,\r\n      \"developer_count\": 0\r\n    },\r\n    {\r\n      \"id\": \"5554fa4019406a0001000003\",\r\n      \"owner_name\": \"Test\",\r\n      \"owner_slug\": \"test\",\r\n      \"apis\": [\r\n        {\r\n          \"api_human_name\": \"HttpBin\",\r\n          \"api_id\": \"bbd1f881d3d14ada6c02fd56d2d39c4b\"\r\n        },\r\n        {\r\n          \"api_human_name\": \"Google\",\r\n          \"api_id\": \"e415d7cd4546498873370868295a70b0\"\r\n        }\r\n      ],\r\n      \"developer_quota\": 0,\r\n      \"developer_count\": 0\r\n    }\r\n  ],\r\n  \"pages\": 0\r\n}\r\n```\r\n\r\nHere's the results I get when I try to navigate to the different URLs with different ports.\r\n\r\n![screen shot 2015-05-14 at 3 51 46 pm](https://cloud.githubusercontent.com/assets/2223120/7640439/45c436ec-fa51-11e4-8a74-b86a02c6e913.png)\r\n![screen shot 2015-05-14 at 3 51 57 pm](https://cloud.githubusercontent.com/assets/2223120/7640440/45c4ee66-fa51-11e4-9523-3e6fec3959b3.png)\r\n![screen shot 2015-05-14 at 3 52 25 pm](https://cloud.githubusercontent.com/assets/2223120/7640441/45c51062-fa51-11e4-9458-2e385da7b063.png)\r\n![screen shot 2015-05-14 at 3 52 19 pm](https://cloud.githubusercontent.com/assets/2223120/7640442/45c57b10-fa51-11e4-9d52-221ed477f12c.png)\r\n\r\nGoing to the APIs directly yields the results that I expect.\r\n![screen shot 2015-05-14 at 3 54 35 pm](https://cloud.githubusercontent.com/assets/2223120/7640510/a292223a-fa51-11e4-8681-d98579161709.png)\r\n![screen shot 2015-05-14 at 3 55 02 pm](https://cloud.githubusercontent.com/assets/2223120/7640511/a292f8ae-fa51-11e4-8575-921da62a4aa0.png)\r\n"}}