Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure Nginx CVM and how to realize reverse proxy function

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

The following shows you how to configure Nginx CVM and how to achieve reverse proxy. I hope it can give you some help in practical application. There are many things involved in load balancing, not many theories, and there are many books on the Internet. Today, we will use the accumulated experience in the industry to do an answer.

Nginx reverse proxy (load balancing)

Use 3 Centos CVM, one of which acts as a Nginx proxy server, 192.168.4.5

The IP addresses of the two Web servers are 192.168.4.205 and 192.168.4.200, respectively.

Configure Nginx server, add server pool, and realize reverse proxy function

Weight weight value, if the customer sends back three connected servers, two of them will be forwarded to 192.168.4.205 and the other to 192.168.1.200.

Max_fails allows the number of failed requests

The time the service is suspended after the fail_timeout request fails.

1) modify / usr/local/nginx/conf/nginx.conf configuration file

[root@svr ~] # vim / usr/local/nginx/conf/nginx.conf

....

Http {

....

Upstream webserver {

Server 192.168.4.205 weight=2 max_fails=2 fail_timeout=10

Server 192.168.4.200 weight=1 max_fails=2 fail_timeout=10

}

....

Server {

Listen 80

Server_name www.tarena.com

Location / {

Proxy_pass http://webserver;

}

}

2) restart the nginx service

[root@svr] # / usr/local/nginx/sbin/nginx-s stop

[root@svr ~] # / usr/local/nginx/sbin/nginx

Deploy and implement a back-end Web server

The backend Web server can simply use yum to install httpd to implement Web service, or you can use Nginx or Tomcat. According to the actual requirements, I will use httpd for convenience.

In order to see the difference between the back-end servers, you can set the first page document content of the two back-end servers to different content.

1) deploy the backend Web1 server

[root@web1 ~] # yum-y install httpd

[root@web1 ~] # echo "192.168.4.205" > / var/www/html/index.html

[root@web1 ~] # service httpd start

2) deploy the backend Web2 server

[root@web2 ~] # yum-y install httpd

[root@web2 ~] # echo "192.168.4.200" > / var/www/html/index.html

[root@web2 ~] # service httpd start

Client test

1) modify the client hosts file

[root@client ~] # vim / etc/hosts

....

172.16.0.254 www.tarena.com

2) use the browser to access the proxy server to test the polling effect

[root@client ~] # curl http://www.tarena.com / / multiple visits to view the results

After reading the above about how to configure Nginx CVM and how to achieve reverse proxy function, if there is anything else you need to know, you can find out what you are interested in in the industry information or find our professional and technical engineers for answers. Technical engineers have more than ten years of experience in the industry. Official website link www.yisu.com

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report