Unsupported protocol scheme ""

I cannot create keys on TYK. Nodes can be seen but when I try to create a key I get this error.

Failed to save new session object to Tyk: Failed to create key: Post 127.0.0.1:10010/tyk/keys/create: unsupported protocol scheme ""

The TYK node is running and is shown as being available.

Both config files point to the correct place but I have no idea what else to try.

Any ideas would be much appreciated.

In the setting in tyk_analytics.conf where you set where the Tyk API is you must include the protocol as well as the hostname, so http://

Hey Martin!

Thanks for the quick response.

Done. restarted both:

Failed to unmarshal error: invalid character 'p' after top-level value

I am guessing that it is connecting to the “wrong thing”. i.e. the response is coming back as HTML or something other than JSON?

this is the config file for the dashboard

{
    "listen_port": 3000,
    "tyk_api_config": {
        "Host": "http://127.0.0.1",
        "Port": "10010",
        "Secret": "XXXXXXXXXXXXXXXXX"
    },

This for for the gateway

"listen_port": 10010,
  "node_secret": "XXXXXXXXXXXXXXXXX",
  "secret": "XXXXXXXXXXXXXXXXX",
  "template_path": "/opt/tyk-gateway/templates",
  "tyk_js_path": "/opt/tyk-gateway/js/tyk.js",
  "use_db_app_configs": true,
  "db_app_conf_options": {
        "connection_string": "http://127.0.0.1:3000",
        "node_is_segmented": false,
        "tags": []
  },

Dashboard error log:

time="Jul  8 05:31:41" level=error msg="Failed to unmarshal error: invalid character 'p' after top-level value"
time="Jul  8 05:31:41" level=warning msg="Failed create:Failed to unmarshal error: invalid character 'p' after top-level value"
time="Jul  8 05:31:41" level=error msg="Failed to save new session object to Tyk: Failed to unmarshal error: invalid character 'p' after top-level value

gateway error log

time="Jul  8 05:25:57" level=info msg="Node registered" id= XXXXXXXX
time="Jul  8 05:25:57" level=info msg="Starting heartbeat."
time="Jul  8 05:25:57" level=info msg="Detected 3 APIs"
time="Jul  8 05:25:57" level=info msg="--> Loading API: This Api "
time="Jul  8 05:25:57" level=info msg="----> Custom Domain: gateway.apithis.com"
time="Jul  8 05:25:57" level=info msg="----> Tracking: gateway.apithis.com"
time="Jul  8 05:25:57" level=info msg="----> Checking security policy: Open"
time="Jul  8 05:25:57" level=info msg="--> Loading API: LINKUPTEST"
time="Jul  8 05:25:57" level=info msg="----> Custom Domain: gateway.apithis.com"
time="Jul  8 05:25:57" level=info msg="----> Tracking: gateway.apithis.com"
time="Jul  8 05:25:57" level=info msg="----> Checking security policy: Token"
time="Jul  8 05:25:57" level=info msg="--> Loading API: Moonster"
time="Jul  8 05:25:57" level=info msg="----> Custom Domain: gateway.moonster.com"
time="Jul  8 05:25:57" level=info msg="----> Tracking: gateway.moonster.com"
time="Jul  8 05:25:57" level=info msg="----> Checking security policy: Token"
time="Jul  8 05:25:57" level=info msg="Loading uptime tests..."
time="Jul  8 05:25:57" level=error msg="Failed to decode body: json: cannot unmarshal string into Go value of type []main.DBPolicy"
time="Jul  8 05:25:57" level=info msg="Gateway started (v2.1.0.0)"
time="Jul  8 05:25:57" level=info msg="--> Listening on port: 10010"

Ports are open and running so I am not sure what is causing the trouble.

I fear it may be me though.

You have a JSON parser error, so you are probably missing a comma or something - I would suggest running your conf through a linter like jsonlint.com

mmm. I thought so too. Double checked both and they are fine.

interesting thing is:

sudo curl http://gateway.api1com
{
    "error": "Authorization field missing"
}

sudo curl http://gateway.api2.com/tyk/keys
{
    "error": "Authorization field missing"
}

sudo curl http://127.0.0.1:10010
404 page not found

Both of the apis have this configuration in the NGINX configuration:

   upstream tyk {

       server 127.0.0.1:10010;

   }

and in the sites-available file:

   location / {

       rewrite /(.*) /dbe0a5556ac741e5621a7fde48e3cdbb/$1 break;
       proxy_pass_header Server;
       proxy_set_header Host $http_host;
       proxy_redirect off;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Scheme $scheme;
       proxy_pass http://tyk/;
  }

I am sure it is something small but it is super frustrating because I cannot figure out for the life of me what it is that I am missing.

Thank you as always for your help Martin. Worth your weight in BItCoin.

Umm.

I made some changes.

Logged out.

Logged in.

it worked.

I dunno why. I will keep tracing my steps and try and post what I did to get this to work.

Double Checked.

Creating keys as admin works ok now.

Creating keys via the portal (signup -> view catalogue -> request key - approve key) does not work. 

time="Jul 11 04:23:37" level=error msg="Trying to create token from cvatalogue with no auth types! No valid API found!"
time="Jul 11 04:23:37" level=error msg="Something went wrong, couldn't get Api detail"
time="Jul 11 04:23:37" level=error msg="not found"
time="Jul 11 04:23:37" level=error msg="Failed to create key: Post http://127.0.0.1:10010/tyk/keys/create: EOF"
time="Jul 11 04:23:37" level=warning msg="Failed create:Failed to create key: Post http://127.0.0.1:10010/tyk/keys/create: EOF"
time="Jul 11 04:23:37" level=error msg="Key creation failed! Failed to create key: Post http://127.0.0.1:10010/tyk/keys/create: EOF"
time="Jul 11 04:23:37" level=error msg="Generation error: Failed to create key: Post http://127.0.0.1:10010/tyk/keys/create: EOF"
time="Jul 11 04:23:37" level=info msg="Email notifications disabled, skipping Send()"
time="Jul 11 04:24:39" level=error msg="Something went wrong, couldn't get Api detail"
time="Jul 11 04:24:39" level=error msg="not found"
time="Jul 11 04:24:39" level=error msg="Trying to create token from cvatalogue with no auth types! No valid API found!"
time="Jul 11 04:24:41" level=error msg="Something went wrong, couldn't get Api detail"
time="Jul 11 04:24:41" level=error msg="not found"
time="Jul 11 04:24:41" level=error msg="Trying to create token from cvatalogue with no auth types! No valid API found!"
time="Jul 11 04:25:10" level=error msg="Something went wrong, couldn't get Api detail"
time="Jul 11 04:25:10" level=error msg="not found"
time="Jul 11 04:25:10" level=error msg="Failed to create key: Post http://127.0.0.1:10010/tyk/keys/create: EOF"
time="Jul 11 04:25:10" level=warning msg="Failed create:Failed to create key: Post http://127.0.0.1:10010/tyk/keys/create: EOF"
time="Jul 11 04:25:10" level=error msg="Key creation failed! Failed to create key: Post http://127.0.0.1:10010/tyk/keys/create: EOF"
time="Jul 11 04:25:10" level=error msg="Generation error: Failed to create key: Post http://127.0.0.1:10010/tyk/keys/create: EOF"
time="Jul 11 04:25:10" level=info msg="Email notifications disabled, skipping Send()"
time="Jul 11 04:27:11" level=error msg="Something went wrong, couldn't get Api detail"
time="Jul 11 04:27:11" level=error msg="not found"
time="Jul 11 04:27:11" level=error msg="Failed to create key: Post http://127.0.0.1:10010/tyk/keys/create: EOF"
time="Jul 11 04:27:11" level=warning msg="Failed create:Failed to create key: Post http://127.0.0.1:10010/tyk/keys/create: EOF"
time="Jul 11 04:27:11" level=error msg="Key creation failed! Failed to create key: Post http://127.0.0.1:10010/tyk/keys/create: EOF"
time="Jul 11 04:27:11" level=error msg="Generation error: Failed to create key: Post http://127.0.0.1:10010/tyk/keys/create: EOF"

The http://127.0.0.1:10010 still returns:

404 page not found

no idea what is going on.

I need to be taken out and fed to some amoeba. Maybe they will make better use of the carbon I am currently wasting.

Policies.

I double checked the policies and the current policy was referencing an API that I no longer used. Hence why the keys were not being created by TYK. This was because I bootstrapped TYK like 8 times (long story).

Everything seems fine for now.

Will try and summarise everything soon and post.

I think the issue is you have mixed configurations

The nginx setup with the upstream proxy is quite an old way of doing it, and assumes that you will be putting all your APIs on a listen path based on their API ID and then manage domains using NginX

However here, you have an NGinX setup, with a rewrite to an API ID, which are you not using, because in your Tyk output you have each API bound to a domain name.

If you need NginX in place, then you’ll need to:

  1. Remove the rewrite altogether
  2. Ensure that host header is proxied by NginX too so that Tyk can read it

OR

  1. Remove the rewrite
  2. Modify the API configs to not use a domain and instead set the domains up in NginX

Either way, your config is a mix between 2.2 and pre-1.8! Which is why you are getting the errors, Tyk is calling 127.0.0.1 and getting a 404, probably because Tyk Gateway isn;t listening on 127.0.0.1, but a domain name, OR the IP + port.

1 Like