Error - 404 Page not found

Hi,

I need some help to figure out what I am missing. I setup vagrant vm and followed all the instructions at https://tyk.io/tyk-documentation/get-started/with-tyk-on-premise/installation/install-tyk-pro-premise-vagrant/.

I was able to add apis (rest request I used is at bottom) and create api_key. I am trying to do a simple test below but keep getting “404 page not found”. Appreciate any pointers.

my-tyk-instance.com:8080/test-api => my-tyk-instance.com:9080/ (9080 is served by a service named rest1)
my-tyk-instance.com:8080/test-api2 => my-tyk-instance.com:9090/ (9090 is served by a service named rest1)

vagrant@precise64:/vagrant$ curl my-tyk-instance.com:9080
Hello, “/” rest1 serving at 9080
vagrant@precise64:/vagrant$ curl my-tyk-instance.com:9080/blah
Hello, “/blah” rest1 serving at 9080
vagrant@precise64:/vagrant$ curl my-tyk-instance.com:9090
Hello, “/” rest2 serving at 9090
vagrant@precise64:/vagrant$ curl my-tyk-instance.com:9090/blah
Hello, “/blah” rest2 serving at 9090

vagrant@precise64:/vagrant$ ./get-api
404 page not found
vagrant@precise64:/vagrant$ cat get-api
curl -H “Authorization: {API-KEY}”
-s
-H “Content-Type: application/json”
-X GET
my-tyk-instance.com:8080/test-api/

vagrant@precise64:/vagrant$ sudo netstat -anp | grep "tyk "
tcp 263 0 127.0.0.1:51700 127.0.0.1:3000 ESTABLISHED 2650/tyk
tcp 0 0 127.0.0.1:51067 127.0.0.1:6379 ESTABLISHED 2650/tyk
tcp 0 0 127.0.0.1:51065 127.0.0.1:6379 ESTABLISHED 2650/tyk
tcp 0 0 127.0.0.1:51113 127.0.0.1:6379 ESTABLISHED 2650/tyk
tcp6 0 0 :::8080 :::* LISTEN 2650/tyk

vagrant@precise64:/vagrant$ sudo netstat -anp | grep a.out
tcp 0 0 127.0.0.1:9080 0.0.0.0:* LISTEN 3037/a.out
tcp 0 0 127.0.0.1:9090 0.0.0.0:* LISTEN 3046/a.out

vagrant@precise64:/vagrant$ cat add-api
curl -H “Authorization: {secret}”
-s
-H “Content-Type: application/json”
-X POST
-d ‘{
“api_definition”: {
“name”: “Test API”,
“slug”: “test-api”,
“auth”: {
“auth_header_name”: “Authorization”
},
“definition”: {
“location”: “header”,
“key”: “x-api-version”
},
“version_data”: {
“not_versioned”: true,
“versions”: {
“Default”: {
“name”: “Default”,
“use_extended_paths”: true
}
}
},
“proxy”: {
“listen_path”: “/test-api/”,
“target_url”: “http://my-tyk-instance.com:9080/”,
“strip_listen_path”: true
},
“active”: true
}
}’
my-tyk-instance.com:3000/api/apis/ | python -mjson.tool

Thanks,
PR

I figured out the problem. I had set custom domain as my-tyk-instance.com:8080. Once I removed it, it started working. Not sure why the custom domain was causing the issue though.

1 Like

I have the same issue having just installed the on-prem version of Tyk. I have setup the dashboard to use a custom domain api.mysite.com

PR1: Can you please elaborate on what setting you updated?
Was it “enable_custom_domains”: false in tyk.conf? I have tried setting this to true but it did not make a difference.

Has anyone else experienced this issue?

Reproduction steps:

Log on dashboard
Go to API’s
Create “test-api” api definiton
Set keyless for Authentication mode
Save
Open api url(in my case http://localhost:8080/test1

Result

  1. Gateway returns 404 error
  2. As expected, if I stop the gateway the browser returns a “This site can’t be reached SERVERNAME refused to connect.”
  3. I can see the from the Gateway logs that the API config has been loaded but the invoking the target APU url does not make an entry in the gateway logs

Gateway logs are as follows:
[Mar 11 14:37:18] INFO main: Setting up analytics normaliser
[Mar 11 14:37:18] INFO main: PIDFile location set to: ./tyk-gateway.pid
[Mar 11 14:37:18] INFO main: Initialising Tyk REST API Endpoints
[Mar 11 14:37:18] INFO host-check-mgr: Starting Poller
[Mar 11 14:37:18] INFO Redis connection pools are ready after number of retires currRetry=0
[Mar 11 14:37:18] INFO Redis connection pools are ready
[Mar 11 14:37:18] INFO main: → Standard listener (http) port=:8080
[Mar 11 14:37:18] INFO main: Initialising distributed rate limiter
[Mar 11 14:37:18] INFO main: Setting up Server
[Mar 11 14:37:18] INFO main: Waiting for zeroconf signal…
[Mar 11 14:37:18] INFO Starting gateway rate limiter notifications…
[Mar 11 14:37:19] WARN pub-sub: Insecure configuration detected (allowing)!
[Mar 11 14:37:19] INFO pub-sub: Hostname set with dashboard zeroconf signal
[Mar 11 14:37:19] INFO main: Registering node.
[Mar 11 14:37:19] INFO dashboard: Node registered id=fdf8cbfc-3115-45c7-7861-2ae10a3e0f20
[Mar 11 14:37:19] INFO main: Gateway started (v2.5.3)
[Mar 11 14:37:19] INFO main: → Listening on address: (open interface)
[Mar 11 14:37:19] INFO main: → Listening on port: 8080
[Mar 11 14:37:19] INFO main: → PID: 4441
[Mar 11 14:37:19] INFO main: Loading policies
[Mar 11 14:37:19] INFO main: Using Policies from Dashboard Service
[Mar 11 14:37:19] INFO policy: Mutex lock acquired… calling
[Mar 11 14:37:19] INFO policy: Calling dashboard service for policy list
[Mar 11 14:37:19] INFO policy: Processing policy list
[Mar 11 14:37:19] INFO main: Policies found (0 total):
[Mar 11 14:37:19] INFO main: Detected 3 APIs
[Mar 11 14:37:19] INFO main: Preparing new router
[Mar 11 14:37:19] INFO main: Initialising Tyk REST API Endpoints
[Mar 11 14:37:19] INFO main: Loading API configurations.
[Mar 11 14:37:19] INFO main: Tracking hostname api_name=httpbin domain=(no host)
[Mar 11 14:37:19] INFO main: Tracking hostname api_name=test1 domain=(no host)
[Mar 11 14:37:19] INFO main: Tracking hostname api_name=test2 domain=(no host)
[Mar 11 14:37:19] INFO main: Loading API api_name=httpbin
[Mar 11 14:37:19] INFO main: Loading API api_name=test1
[Mar 11 14:37:19] INFO main: Loading API api_name=test2
[Mar 11 14:37:19] INFO main: Checking security policy: Open api_name=httpbin
[Mar 11 14:37:19] INFO gateway: Loaded: httpbin api_id=80482d80d15c4d646b7f3e5ee047172e org_id=5aa4e41461451e77ccb74257 server_name=-- user_id=-- user_ip=–
[Mar 11 14:37:19] INFO main: Checking security policy: Open api_name=test1
[Mar 11 14:37:19] INFO gateway: Loaded: test1 api_id=c5f94d7b6541449970357e21d9d5ccd5 org_id=5aa4e41461451e77ccb74257 server_name=-- user_id=-- user_ip=–
[Mar 11 14:37:19] INFO main: Checking security policy: Open api_name=test2
[Mar 11 14:37:19] INFO gateway: Loaded: test2 api_id=4f1747a9ee2344bf7532973df339db4a org_id=5aa4e41461451e77ccb74257 server_name=-- user_id=-- user_ip=–
[Mar 11 14:37:19] INFO main: Processed and listening on: /httpbin/{rest:.}
[Mar 11 14:37:19] INFO main: Processed and listening on: /test1/{rest:.
}
[Mar 11 14:37:19] INFO main: Processed and listening on: /test2/{rest:.*}
[Mar 11 14:37:19] INFO host-check-mgr: Loading uptime tests…
[Mar 11 14:37:19] INFO main: Initialised API Definitions
[Mar 11 14:37:19] INFO main: API reload complete

/opt/tyk-gateway$ cat tyk.conf
{
“listen_port”: 8080,
“node_secret”: “352d20ee67be67f6340b4c0605b044b7”,
“secret”: “352d20ee67be67f6340b4c0605b044b7”,
“template_path”: “/opt/tyk-gateway/templates”,
“use_db_app_configs”: true,
“db_app_conf_options”: {
“connection_string”: “”,
“node_is_segmented”: false,
“tags”: []
},
“disable_dashboard_zeroconf”: false,
“app_path”: “/opt/tyk-gateway/apps”,
“middleware_path”: “/opt/tyk-gateway/middleware”,
“storage”: {
“type”: “redis”,
“host”: “localhost”,
“port”: 6379,
“username”: “”,
“password”: “”,
“database”: 0,
“optimisation_max_idle”: 2000,
“optimisation_max_active”: 4000
},
“enable_analytics”: true,
“analytics_config”: {
“type”: “”,
“ignored_ips”: [],
“enable_detailed_recording”: true,
“enable_geo_ip”: false,
“geo_ip_db_path”: “”,
“normalise_urls”: {
“enabled”: true,
“normalise_uuids”: true,
“normalise_numbers”: true,
“custom_patterns”: []
}
},
“health_check”: {
“enable_health_checks”: false,
“health_check_value_timeouts”: 60
},
“optimisations_use_async_session_write”: true,
“allow_master_keys”: false,
“policies”: {
“policy_source”: “service”,
“policy_connection_string”: “”,
“policy_record_name”: “tyk_policies”,
“allow_explicit_policy_id”: true
},
“hash_keys”: true,
“suppress_redis_signal_reload”: false,
“use_redis_log”: true,
“close_connections”: true,
“enable_non_transactional_rate_limiter”: true,
“enable_sentinel_rate_limiter”: false,
“local_session_cache”: {
“disable_cached_session_state”: false
},
“http_server_options”: {
“enable_websockets”: true
},
“uptime_tests”: {
“disable”: false,
“config”: {
“enable_uptime_analytics”: true,
“failure_trigger_sample_size”: 2,
“time_wait”: 10,
“checker_pool_size”: 50
}
},
“hostname”: “”,
“enable_custom_domains”: false,
“enable_jsvm”: true,
“oauth_redirect_uri_separator”: “;”,
“coprocess_options”: {
“enable_coprocess”: false,
“coprocess_grpc_server”: “”
},
“pid_file_location”: “./tyk-gateway.pid”,
“allow_insecure_configs”: true,
“public_key_path”: “”,
“close_idle_connections”: false,
“allow_remote_config”: false,
“enable_bundle_downloader”: true,
“bundle_base_url”: “”,
“global_session_lifetime”: 100,
“force_global_session_lifetime”: false,
“max_idle_connections_per_host”: 100
}

Hi Martin

I managed to solve the issue.

It’s embarrassingly simple.

The Listen Path on the API configured in Tyk gateway was set to /test2/ where as I was invoking the URL without the final forward slash http://api.mydomain.com:8080/test2

When I modify the Listen path to /test2 (without the forward slash) it works both ways.

Not sure if this is a bug as it is quite confusing. But I am pleased I now have a working instance running

Thanks,
Marcus