docker - How to hide my API connection between microservices using Docker?
问题描述
I'm new with Docker and I'm setting up a new application where I have 2 services on my docker-compose file:
# Contains all my API servers
api_load_balancer:
build: ./microservices/load_balancer
restart: always
ports:
- "8080:80"
# Contains all my client servers
server_client:
build: ./microservices/client
ports:
- "80:80"
....
My microservices/load_balancer nginx.conf looks like this:
events { worker_connections 1024; }
http{
include /etc/nginx/mime.types;
default_type application/octet-stream;
upstream api_nodes {
server api_1:9000;
}
upstream socket_nodes {
ip_hash;
server socketio_1:5000;
}
# SERVER API
server {
location /socket.io/ {
proxy_set_header Access-Control-Allow-Origin *;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://socket_nodes;
# enable WebSockets
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /api/ {
proxy_set_header Access-Control-Allow-Origin *;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://api_nodes;
}
}
}
My load_balancer/Dockerfile looks like this:
FROM nginx:alpine
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY ./ssl ./etc/nginx/ssl
EXPOSE 80
When I try to connect from my client I'm able to do it from my client's server (using the api_load_balancer connection string as they're in the same docker network), but, when I try to do a call from the browser I need to change my connection string to something like localhost:8080 or some.ip.in.public.server:8080.
I don't like the idea of exposing neither my port nor my API configuration like that, so is there any way that I can implement a more transparent connection between those microservices? I don't know if it's even possible to do so.
解决方案
推荐阅读
- javascript - 如何在按键后跳转,向上箭头,
- python - 使用 pandas 中的列子集
- visual-studio-code - 如何让 editor.wordWrap 仅在 VSCode 中的特定上下文或范围内工作?
- arrays - 通过它的选项组检索选择的选定值
- r - 如何在R中绘制笛卡尔平面?
- spring-batch - 如何运行春季批处理 JSR 352
- java - IntelliJ 没有开始测试,无法开始:1,通过:0
- html - 使用 Oracle PL/SQL 将 Quill Editor 生成的 HTML 转换为简单的 HTML
- javascript - 为什么我使用 keycloak-angular 库被重定向到登录屏幕?
- android - 类型不匹配。必需:流
> 发现:流 >>