Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions Dmitry_Predko/Hometask_7:docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
version: '3.4'
services:
load-balancer:
image: nginx:latest
container_name: load-balancer
volumes:
- ./load-balancer-nginx.conf:/etc/nginx/nginx.conf:ro
- ./ssl:/etc/nginx/ssl:ro
restart: always
depends_on:
- nginx_node1
- nginx_node2
ports:
- '80:80'
- '443:443'
networks:
- backend
healthcheck:
test: ["CMD", "service", "nginx", "status"]
interval: 1m
timeout: 10s
retries: 3
start_period: 40s
logging:
driver: journald
options:
tag: load-balancer

nginx_node1:
image: nginx:latest
container_name: nginx_node1
volumes:
- ./site:/var/www/html
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./htpasswd:/etc/nginx/conf/htpasswd:ro
#- ./ssl:/etc/nginx/ssl:ro
restart: always
expose:
- '80'
- '443'
networks:
- backend
healthcheck:
test: ["CMD", "service", "nginx", "status"]
interval: 1m
timeout: 10s
retries: 3
start_period: 40s
logging:
driver: journald
options:
tag: nginx_node1

nginx_node2:
image: nginx:latest
container_name: nginx_node2
volumes:
- ./site:/var/www/html
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./htpasswd:/etc/nginx/conf/htpasswd:ro
#- ./ssl:/etc/nginx/ssl:ro
restart: always
expose:
- '80'
- '443'
networks:
- backend
healthcheck:
test: ["CMD", "service", "nginx", "status"]
interval: 1m
timeout: 10s
retries: 3
start_period: 40s
logging:
driver: journald
options:
tag: nginx_node2

networks:
backend:
driver: bridge
41 changes: 41 additions & 0 deletions Dmitry_Predko/Hometask_7:docker/load-balancer-nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
multi_accept on;
}

http {
upstream backend {
least_conn;
server nginx_node1;
server nginx_node2;
}

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m use_temp_path=off;

server {
listen 80;
listen 443 ssl http2;
server_name .dimon.com;

add_header Cache-Control "public";

ssl_certificate /etc/nginx/ssl/domain.crt;
ssl_certificate_key /etc/nginx/ssl/domain.key;

location / {
proxy_cache my_cache;
proxy_pass http://backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
77 changes: 77 additions & 0 deletions Dmitry_Predko/Hometask_7:docker/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
multi_accept on;
}

http {
error_page 404 /404.html;

include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain application/xml;

server {
listen 80;
server_name dimon.com;

add_header Cache-Control "public";

location / {
root /var/www/html/jony;
}

location ~* \.(jpg|jpeg|gif|png|ico)$ {
root /var/www/html/jony;
expires 30d;
}

location ~* \.(css|js)$ {
root /var/www/html/jony;
expires 1d;
}
}

server {
listen 80;
server_name cv.dimon.com;

location / {
root /var/www/html/cv;
}
}

server {
listen 80;
server_name admin.dimon.com;

location / {
auth_basic "closed site";
auth_basic_user_file conf/htpasswd;
root /var/www/html/admin;
}

}
include /etc/nginx/conf.d/*.conf;
}