My First Load Balancer
I write this post as a requirement for my tenth PPW lab assignment. I would like to share my experience on using nginx for the first time. The project was limited to localhost. To start it off, i created a basic application using django, to display the port it is ran on. Then i used the command “manage.py runserver 8000” and “manage.py runserver 9000” to simulate 2 servers running the application. Afterwards i configure my nginx.conf file to be
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| events { worker_connections 1024;}http{ upstream localhost { server 127.0.0.1:8000; server 127.0.0.1:9000; } server { listen 80; server_name localhost; location / { proxy_pass http://localhost; } }} |
Then i ran nginx and reload the configuration to apply the new file. Afterwards i opened port 80 through my browser and the app would alternatively display 8000 and 9000 each time i opened a new instance of the localhost:80. And there you have it, a simple example for nginx in localhost
No comments:
Post a Comment