0

I'm using docker with compose and I've created some microservices and I'm trying to connect them through Kong Gateway.

To access the MSs with PHP I created in Nginx the reverse proxy where I can access through the URLS example below:

http://service1.localhost:8081 (Laravel with PHP MS)
http://service2.localhost:8081 (Laravel with PHP MS)
http://service3.localhost:8081 (Laravel with PHP MS)

http://frontend.localhost:8080 (Nuxt JS With Node MS)

The question is, i have a container only with Nginx that allows me to use the other microservices in the way mentioned above through the reverse proxy, but the MSs URLS in Laravel have the example paths:

/api/v1/abc /api/v1/abc/def /api/v1/def /api/v1/def/123 /api/v1/abc/abcd-efg

That is, they have several paths "in depth". And when I'm trying to insert these URLs into Kong I'm getting the error when accessing them:

"An invalid response was received from the upstream server"

And in the browser it points as 502; I understand that the 502 is Bad Gateway, so I believe the error may be in the settings I'm using in the Nginx conf file.

My Nginx configuration is as follows (1 file for each MS in Laravel, just changing the path and subdomain of the url):

server {
    listen 80;
    listen [::]:80;
    server_name service1.localhost;
    
    root /var/www/service1/public;

    error_log  /var/log/nginx/error.logs;
    access_log /var/log/nginx/access.logs;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";
 
    index index.php;
 
    charset utf-8;
 
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
 
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
 
    error_page 404 /index.php;
 
    location ~ \.php$ {
        fastcgi_pass service1.localhost:9000;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;        
    }
 
    location ~ /\.(?!well-known).* {
        deny all;
    }
}

In the docker logs, in the Kong container I am seeing these errors below:

[error] 2140#0: *13211 connect() failed (111: Connection refused) while connecting to upstream, client: 172.19.0.1, server: kong, request: "GET /api/v1/states HTTP/1.1", upstream: "http://172.19.0.2:8000/api/v1/states", host: "localhost:8000"
    [error] 2140#0: *13211 connect() failed (111: Connection refused) while connecting to upstream, client: 172.19.0.1, server: kong, request: "GET /api/v1/states HTTP/1.1", upstream: "http://172.19.0.2:8000/api/v1/states", host: "localhost:8000"
    [error] 2140#0: *13211 connect() failed (111: Connection refused) while connecting to upstream, client: 172.19.0.1, server: kong, request: "GET /api/v1/states HTTP/1.1", upstream: "http://172.19.0.2:8000/api/v1/states", host: "localhost:8000"
    [error] 2140#0: *13211 connect() failed (111: Connection refused) while connecting to upstream, client: 172.19.0.1, server: kong, request: "GET /api/v1/states HTTP/1.1", upstream: "http://172.19.0.2:8000/api/v1/states", host: "localhost:8000"
    [error] 2140#0: *13211 connect() failed (111: Connection refused) while connecting to upstream, client: 172.19.0.1, server: kong, request: "GET /api/v1/states HTTP/1.1", upstream: "http://172.19.0.2:8000/api/v1/states", host: "localhost:8000"
    [error] 2140#0: *13211 connect() failed (111: Connection refused) while connecting to upstream, client: 172.19.0.1, server: kong, request: "GET /api/v1/states HTTP/1.1", upstream: "http://172.19.0.2:8000/api/v1/states", host: "localhost:8000"

Since the internal IP of the service1 container is 179.19.0.2, and this 179.19.0.1 is the Gateway IP. All microservices are on the same network. I have already entered these addresses in the windows hosts file.

192.168.0.109 host.docker.internal
192.168.0.109 gateway.docker.internal

And I'm also using the "extra_hosts" configuration in all micro services:

extra_hosts:
  - "host.docker.internal:host-gateway"

I've tried the configuration in Kong in several ways, I've watched several tutorials, I've seen several examples, but no video or article showed the example as a micro service with reverse proxy in the sub domain...

I've already tried to put the configuration in Kong to search for the url (service1.localhost:8081), I've already tried the internal IP (172.19.0.2:8081), with the internal port that MS was sharing (49154) and no way worked.

PS: I'm using WSL2, I don't know if it's relevant, but in case anyone is interested...

0 Answers0