如果我问了一个愚蠢的问题,请原谅我,但我正在构建一个服务器,我将使用 Nginx Docker 在该服务器上托管多个 Flask 网站 Docker 容器。我现在的问题是:是有一个主 nginx docker 容器然后在其上托管我所有的网站 Docker 容器更好,还是使用 docker compose 为每个应用程序提供一个 Nginx docker 容器更好?
我想知道从资源处理和效率方面来说哪一个更好?
@Jacob 根据你的回答,我正在尝试设置类似的东西
docker-compose.yml:
version: "3.8"
services:
portfolix:
container_name: portfolix
image: mervin16/portfolix:dev
env_file:
- config_local.env
expose:
- 8086
restart: always
networks:
- sky_net
mes:
container_name: mes
image: mervin16/mes:dev
networks:
- sky_net
expose:
- 8085
restart: always
nginx:
build: ./nginx
container_name: nginx
ports:
- "8085:85"
- "8086:86"
restart: always
networks:
- sky_net
networks:
sky_net:
name: sky_network
driver: bridge
现在每个网站都可以在 localhost:8085 和 localhost:8086 上访问
然后,我使用 Nginx 上的反向代理(不是 docker,而是安装在我服务器上的代理)将流量重定向到我的域名:
server {
server_name mes.th3pl4gu3.com;
location / {
access_log /var/log/nginx/mes/access_mes.log;
error_log /var/log/nginx/mes/error_mes.log;
proxy_pass http://localhost:8081;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mes.th3pl4gu3.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mes.th3pl4gu3.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = mes.th3pl4gu3.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name mes.th3pl4gu3.com;
return 404; # managed by Certbot
}