我有一个在我的localhost中运行app.dev域的应用程序。但是,我想要使用不同的端口运行其他应用程序。而不是端口80,它将是app2的域app.dev:2000 2000 /我可能知道我应该对我的docker-compose和nginx做出什么改变?感谢
这是我的docker-compose
version: "2"
volumes:
mongostorage:
services:
app:
build: ./app
ports:
- "3000"
links:
- mongo
- redis
command: node ./bin/www
app2:
build: ./app2
ports:
- "2000"
links:
- mongo
- redis
command: node app.js
nginx:
build: ./nginx
ports:
- "80:80"
links:
- app:app
mongo:
image: mongo:latest
environment:
- MONGO_DATA_DIR=/data/db
volumes:
- mongostorage:/data/db
ports:
- "27017:27017"
redis:
image: redis
volumes:
- ./data/redis/db:/data/db
ports:
- "6379:6379"
这是我的ngnix.conf
events {
worker_connections 1024;
}
http{
upstream app.dev{
least_conn;
server app:3000 weight=10 max_fails=3 fail_timeout=30s;
}
server {
listen 80;
server_name app.dev;
location / {
proxy_pass http://app.dev;
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 :(得分:0)
我认为只需按以下方式更改app2的端口即可,因为nginx只能侦听端口80.
app2:
build: ./app2
ports:
- "2000:2000"
links:
- mongo
- redis
command: node app.js
答案 1 :(得分:0)
最简单的方法是在端口2000上公开app2
dbconn.ConnectionString = "Driver={Oracle in OraClient11g_home1};Uid=" & <username> & ";Pwd=" & <password> & ";DBQ=XE_DSN"
dbconn.ConnectionString = "Driver={Microsoft ODBC for Oracle};Uid=" & <username> & ";Pwd=" & <password> & ";Server=XE_DSN"
另一种是通过nginx路由连接,以与第一个应用程序保持一致。
撰写
app2:
build: ./app2
ports:
- '2000:2000'
Nginx的
nginx:
build: ./nginx
ports:
- '80:80'
- '2000:2000'
顺便说一下,在版本2+撰写文件中不需要任何http{
upstream app.dev{
least_conn;
server app:3000 weight=10 max_fails=3 fail_timeout=30s;
}
upstream app2.dev{
least_conn;
server app2:2000 weight=10 max_fails=3 fail_timeout=30s;
}
server {
listen 80;
server_name app.dev;
location / {
proxy_pass http://app.dev;
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;
}
}
server {
listen 2000;
server_name app.dev;
location / {
proxy_pass http://app2.dev/;
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;
}
}
}
。您已经可以通过服务名称访问所有服务。