A simple Nginx Load Balancer implemented with 3 Nginx docker containers.
Last active
July 18, 2021 01:06
-
-
Save HuakunShen/3647af3c0005b31e133117b296941b21 to your computer and use it in GitHub Desktop.
Nginx Load Balancer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.9' | |
services: | |
server1: | |
image: nginx | |
volumes: | |
- ./index-1.html:/usr/share/nginx/html/index.html | |
server2: | |
image: nginx | |
volumes: | |
- ./index-2.html:/usr/share/nginx/html/index.html | |
loadbalancer: | |
image: nginx | |
volumes: | |
- ./loadbalancer.config:/etc/nginx/conf.d/default.conf | |
ports: | |
- 80:80 | |
depends_on: | |
- 'server1' | |
- 'server2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Server 1</title> | |
</head> | |
<body> | |
<h1>Server 1</h1> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Server 2</title> | |
</head> | |
<body> | |
<h1>Server 2</h1> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream backend { | |
server server1; | |
server server2; | |
} | |
server { | |
listen 80; | |
listen [::]:80; | |
server_name localhost; | |
location / { | |
proxy_pass http://backend; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment