KalanyuZ
KalanyuZ

Reputation: 682

axios ECONNREFUSED when requesting in a docker-compose service behind nginx reverse proxy

I have two docker-compose setup, the main service is an SPA containing:

This runs behind another docker-compose which is basically an nginx-reverse proxy.

The SPA manages to serve website and connects to backend API via reverse proxy just fine. However, when I try to make a separate https request to the backend api from the server.js I get this message: { Error: connect ECONNREFUSED 127.0.0.1:443 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1121:14) errno: 'ECONNREFUSED', code: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 443 } And it's not just axios, plain wget to the backend url gives me connection refused as well. A sample for said request:

axios.put('/wc/v3/orders/934', { status: "completed" },{ withCredentials:true, auth: { username: process.env.REACT_APP_WC_ADMIN_CK_KEY, password: process.env.REACT_APP_WC_ADMIN_CS_KEY } }).then(function (response) { console.log(`ok`); }).catch(function (error) { console.log(error); });

Any one knows what might be the problem here?

Upvotes: 2

Views: 4197

Answers (1)

Shoan
Shoan

Reputation: 4078

If you have multiple docker-compose environments, then each brings up its own network by default. You want to share the network between the two to allow for the services in one environment to communicate to the other.

# spa/docker-compose.yml
version: '2'
services:
  spa:
    ...
    networks:
      - app-net
networks:
  app-net:
    driver: bridge

.

# express/docker-compose.yml
version: '2'
services:
  api:
    ...
    networks:
      - spa_app-net
networks:
  spa_app-net:
    external: true

Upvotes: 1

Related Questions