如何配置Nginx以在节点上请求多个微服务

时间:2018-11-27 14:26:41

标签: node.js docker nginx microservices

我正在尝试配置nginx来管理所有请求并重定向到节点/表达式上的适当微服务。所有微服务都可以正常工作,可以连接到Redis和Postgres。

我想在不使用URL的情况下进行管理,例如...

我当前正在使用具有多个图像的Docker,这是最相关的文件。

有什么主意吗?谢谢!

docker-compose.yml version: '3' services: nginx: build: ./nginx links: - auth:auth - banks:banks - users:users ports: - "80:80" amplify: build: ./docker-nginx-amplify environment: - API_KEY= - AMPLIFY_IMAGENAME=development auth: build: ./api-auth environment: - PG_SERVER=172.19.0.3 links: - redis - postgres - banks ports: - "8888" banks: build: ./api-banks environment: - PG_SERVER=172.19.0.3 links: - redis - postgres ports: - "8888" users: build: ./api-users environment: - PG_SERVER=172.19.0.3 links: - redis - postgres ports: - "8888" redis: image: redis ports: - "6379" postgres: image: postgres hostname: postgres ports: - "5432:5432" environment: POSTGRES_USER: postgresuser POSTGRES_PASSWORD: postgresuser POSTGRES_DB: privatedatabase restart: unless-stopped nginx.conf

worker_processes 4;
events { worker_connections 1024; }
http {
    upstream node-app {
        least_conn;
        server auth:8888 weight=10 max_fails=3 fail_timeout=30s;
        server banks:8888 weight=10 max_fails=3 fail_timeout=30s;
       server users:8888 weight=10 max_fails=3 fail_timeout=30s;
    }
    server {
        listen 80;


location / {
        proxy_pass http://node-app;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

}

0 个答案:

没有答案