2017年2月8日 星期三

multi docker nginx + nodejs 心得


  1. 用nginx prxoy 可以mapping到不同的image,但外部可以持續用相同的cookie . 
  2. 多專案debug時,直接用內網ip做 proxy_pass就可以了
  3. 用docker-compose做 multi docker,做link後,所有的port都不需要開到外部去,增加安全性.



server {
listen 80;
server_name localhost;
location /test {
proxy_pass http://app:3000/test; # proxy_pass http://192.168.1.100:3000/test;
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;
}
location / {
proxy_pass http://app2:3001; # proxy_pass http://192.168.1.100:3001;
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;
}
location /parse {
proxy_pass http://parse-server:1337/parse; # proxy_pass http://192.168.1.100:1337/parse;
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;
}
} docker-compose.yml <
version: '2'
services:
app:
image: "node:latest"
working_dir: /usr/src/app
command: ./run-dev.sh
volumes:
- ./app:/usr/src/app
environment:
- port=3000
depends_on:
- parse-server
app2:
image: "node:latest"
working_dir: /usr/src/app
command: ./run-dev.sh
volumes:
- ./app:/usr/src/app
environment:
- port=3001
depends_on:
- parse-server
mongo:
image: "mongo"
parse-server:
image: yongjhih/parse-server
# ports:
# - "1337:1337"
environment:
PORT: 1337
DATABASE_URI: "mongodb://mongo:27017/test"
APP_ID: "test"
MASTER_KEY: test_MASTER_KEY
JAVASCRIPT_KEY: test_JAVASCRIPT_KEY
links:
- mongo
depends_on:
- mongo
nginx:
image: nginx
ports:
- "5010:80"
volumes:
- ./proxy/conf.d:/etc/nginx/conf.d
links:
- parse-server
- mongo
- app
- app2

沒有留言:

張貼留言