Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
hsz1273327 committed Dec 4, 2020
1 parent 4de14a9 commit 71c4f5e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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下.

## 依赖

Expand All @@ -10,4 +10,4 @@
## 使用

+ 执行容器可以在`该项目根目录下`打开`terminal`使用`docker-compose up -d`
+ 浏览器中打开页面`https://localhost:5000`可以看到百度的页面
+ 浏览器中打开页面`https://localhost:5000`可以看到`/`下是C0的接口,`/api/`下是C2的接口
7 changes: 7 additions & 0 deletions conf/docker-env.json
Original file line number Diff line number Diff line change
@@ -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"
}
8 changes: 0 additions & 8 deletions config/conf.d/httpproxy.d/forward_proxy.conf

This file was deleted.

18 changes: 18 additions & 0 deletions config/conf.d/httpproxy.d/reverse_proxy.conf
Original file line number Diff line number Diff line change
@@ -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/; #设定代理服务器的协议和地址
}
}
36 changes: 35 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
version: "3.6"
services:
http-static:
http-reverse-proxy:
image: nginx:alpine
networks:
- rest_test
ports:
- 5000:5000
logging:
Expand All @@ -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:

0 comments on commit 71c4f5e

Please sign in to comment.