In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Today, I would like to share with you how to use nginx and docker to achieve a simple load balancing related knowledge, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you can learn something after reading this article, let's take a look at it.
Test steps:
1. Set up a nginx server in the server and start it
two。 Pull nginx's official image, docker pull nginx, from the source in docker, and keep it for backup.
3. Create two new folders in the local directory, and my new folder here is in / mydata/test1,/mydata/test2/
4. Create a new index.html in two test folders to mark, output this is nginx1 in the first html and this is nginx2 in the second html
5. Run the containers of the two nginx servers through docker and map the static directory to the directory we just created
[root@catchtouch test2] # docker run-- name nginx-test-d-p 8080 root@catchtouch test2 80-v / mydata/test1:/usr/share/nginx/html nginx # first, map port 8080 to port 80 in the container [root@catchtouch test2] # docker run-- name nginx-test1-d-p 8081 name nginx-test 80-v / mydata/test2:/usr/share/nginx/html nginx # second, map port 8081 in the container to port 80 in the container
6. Modify the configuration file of nginx in the host
Add the following code to http {}
If upstream myweb {# myproject is a custom name # ip_hash; #, it can be allocated in the form of ip address, which can solve the sesson problem. The larger the server 127.0.0.1 server 8080 weight=1; # weight, the higher the weight, the greater the probability of being assigned. I am all on the local machine, so I use the local ip, as long as it is changed to the corresponding ip or domain name.
7. Go to the conf.d directory and modify default.conf (there is no new file in conf.d, the file name is optional, and the suffix must be .conf)
Location / {# if the server wants to get the real ip of the client, you can use the following three sentences to set the host header and the real address of the client # proxy_set_header host $host; # proxy_set_header x-real-ip $remote_addr; # proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; root / usr/share/nginx/html; index index.html index.htm; proxy_pass http://myweb; # myweb is the name previously defined after upstream in nginx.conf}
8. Exit after saving and restart the server: systemctl restart nginx
9. Enter the current domain name through the browser, and refresh the page, sometimes output nginx1, sometimes output nginx2, configuration is successful
These are all the contents of the article "how to use nginx and docker to achieve a simple load balancing". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.