Reverse proxy
1. docker-compose.yaml
version: '3.5'
services:
db:
hostname: mysql
image: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: "parvin@"
# volumes:
# - db_data:/var/lib/mysql
ports:
- "1111:3306"
# networks:
# critical_network:
docker2-1:
hostname: docker2
image: docker2-student1:v1
restart: always
ports:
- "1234:9090"
environment:
DB_CONNECTION_IP: "mysql"
DB_CONNECTION_PORT: "3306"
DB_CONNECTION_USERNAME: root
DB_CONNECTION_PASSWORD: parvin@
# networks:
# critical_network:
depends_on:
- db
docker2-2:
hostname: docker2
image: docker2-student2:v1
restart: always
ports:
- "1235:9090"
environment:
DB_CONNECTION_IP: "mysql"
DB_CONNECTION_PORT: "3306"
DB_CONNECTION_USERNAME: root
DB_CONNECTION_PASSWORD: parvin@
# networks:
# critical_network:
depends_on:
- db
reverse-proxy:
image: nginx
hostname: proxy
container_name: reverse_proxy
depends_on:
- docker2-1
- docker2-2
ports:
- "8000:80"
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
#networks:
# critical_network:
#volumes:
# db_data:
2. nginx.conf
events {
worker_connections 1024;
}
http {
server {
listen 80;
listen [::]:80;
server_name localhost;
location /student1 {
proxy_pass http://docker2-1:9090/student1;
}
location /student2 {
proxy_pass http://docker2-2:9090/student2;
}
location / {
proxy_pass http://docker2-2:9090/student1;
}
}
}
Комментарии
Отправить комментарий