diff --git a/README.md b/README.md index fbe1eb1..71737b7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# 正向代理示例 +# 反向代理示例 -这个例子代理了百度到本地的5000端口 +这个例子代理[使用Javascript构建RESTful接口服务](https://tutorialforjavascript.github.io/%E4%BD%BF%E7%94%A8Javascript%E6%90%AD%E5%BB%BA%E5%90%8E%E7%AB%AF%E6%9C%8D%E5%8A%A1/RESTful%E6%8E%A5%E5%8F%A3%E6%9C%8D%E5%8A%A1.html)文中的[C0](https://github.com/TutorialForJavascript/js-server/tree/master/code/RESTful%E6%8E%A5%E5%8F%A3%E6%9C%8D%E5%8A%A1/C0)和[C2](https://github.com/TutorialForJavascript/js-server/tree/master/code/RESTful%E6%8E%A5%E5%8F%A3%E6%9C%8D%E5%8A%A1/C2)两个例子,这两个例子都已经打包好了上传在我的dockerhub下. ## 依赖 @@ -10,4 +10,4 @@ ## 使用 + 执行容器可以在`该项目根目录下`打开`terminal`使用`docker-compose up -d` -+ 浏览器中打开页面`https://localhost:5000`可以看到百度的页面 ++ 浏览器中打开页面`https://localhost:5000`可以看到`/`下是C0的接口,`/api/`下是C2的接口 diff --git a/conf/docker-env.json b/conf/docker-env.json new file mode 100644 index 0000000..3b78883 --- /dev/null +++ b/conf/docker-env.json @@ -0,0 +1,7 @@ +{ + "PORT": 3000, + "HOST": "0.0.0.0", + "DB_URL": "postgresql://postgres:postgres@pg-store:5432/postgres", + "REDIS_URL": "redis://redis-channel", + "REDIS_CHANNEL": "test_channel" +} \ No newline at end of file diff --git a/config/conf.d/httpproxy.d/forward_proxy.conf b/config/conf.d/httpproxy.d/forward_proxy.conf deleted file mode 100644 index fb802d4..0000000 --- a/config/conf.d/httpproxy.d/forward_proxy.conf +++ /dev/null @@ -1,8 +0,0 @@ -server { - resolver 114.114.114.114; #指定DNS服务器IP地址 - listen 5000; - server_name localhost; - location / { - proxy_pass http://www.baidu.com; #设定代理服务器的协议和地址 - } -} \ No newline at end of file diff --git a/config/conf.d/httpproxy.d/reverse_proxy.conf b/config/conf.d/httpproxy.d/reverse_proxy.conf new file mode 100644 index 0000000..f0c6ca5 --- /dev/null +++ b/config/conf.d/httpproxy.d/reverse_proxy.conf @@ -0,0 +1,18 @@ +upstream notification { + server rest-notifucation:3000; +} + +upstream helloworld { + server rest-helloworld:3000; +} + +server { + listen 5000; + server_name localhost; + location = / { + proxy_pass http://helloworld; #设定代理服务器的协议和地址 + } + location /api/ { + proxy_pass http://notification/; #设定代理服务器的协议和地址 + } +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index f4ea44a..5682c87 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,9 @@ version: "3.6" services: - http-static: + http-reverse-proxy: image: nginx:alpine + networks: + - rest_test ports: - 5000:5000 logging: @@ -12,3 +14,35 @@ services: - ./config/nginx.conf:/etc/nginx/nginx.conf - ./config/conf.d:/etc/nginx/conf.d + redis-channel: + image: redis:latest + networks: + - rest_test + + pg-store: + image: postgres:latest + networks: + - rest_test + + rest-helloworld: + image: hsz1273327/js-server:restful_c0 + ports: + - 3001:3000 + networks: + - rest_test + + rest-notifucation: + image: hsz1273327/js-server:restful_c3 + depends_on: + - pg-store + - redis-channel + networks: + - rest_test + ports: + - 3002:3000 + volumes: + - ./conf:/conf + command: ./node_modules/.bin/babel-node server/index.js --config /conf/docker-env.json + +networks: + rest_test: