Quantcast
Channel: Active questions tagged containers - DevOps Stack Exchange
Viewing all articles
Browse latest Browse all 164

Access API on a container from another container

$
0
0

I have 2 containers A and B which both contains webapps

A is listening on 443 (apache2)
B is listening on 4000 (node.js)

Since I need to access to both services with https from my machine (win10), I created a reverse proxy with nginx container

N is listening on 443 (nginx)

diagram

A and N are on the network AN
B and N are on the network BN

I added these lines to hosts file on Win10

127.0.0.1 serviceA.company.com127.0.0.1 serviceB.company.com

From my machine I can access to service A with https://serviceA.company.com and service B with https://serviceB.company.com.

Now container B needs to access API on container A via https://serviceA.company.com but it gives me this message :

$ curl -I https://serviceA.company.comcurl: (7) Failed to connect to serviceA.company.com port 443: Connection refused

Here's my nginx conf for reverse proxy

upstream container_a {  server container_a_app:443;}upstream container_b {  server container_b_app:4000;}ssl_session_cache   shared:SSL:10m;ssl_session_timeout 10m;ssl_protocols       TLSv1.2 TLSv1.3;ssl_certificate     /certs/company.com.chained.crt;ssl_certificate_key /certs/company.com.key;ssl_prefer_server_ciphers   on;ssl_ciphers                 ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;proxy_set_header   Host $host;proxy_set_header   X-Real-IP $remote_addr;proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header   X-Forwarded-Host $server_name;proxy_set_header   Upgrade $http_upgrade;proxy_set_header   Connection "upgrade";proxy_redirect       off;proxy_http_version   1.1;proxy_read_timeout      300;proxy_connect_timeout   300;proxy_send_timeout      300;fastcgi_buffers       16 16k;fastcgi_buffer_size   32k;server_tokens         off;server {  listen 443 ssl http2;  server_name serviceB.company.com;  proxy_buffer_size           128k;  proxy_buffers               4 256k;  proxy_busy_buffers_size     256k;  add_header   Strict-Transport-Security "max-age=31536000; includeSubDomains" always;  location / {    proxy_pass   http://container_b;  }}server {  listen 443 ssl http2;  server_name serviceA.company.com;  add_header   Strict-Transport-Security "max-age=31536000; includeSubDomains" always;  location / {    proxy_pass   https://container_a;  }}

Viewing all articles
Browse latest Browse all 164

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>