Structure two files:

Configuration of the upstream. Conf

upstream backends {
     server localhost:10086;
     server localhost:10087;
     server localhost:10088;
}
server {
     listen 80; location / { proxy_pass http://backends; }}Copy the code

backend.conf

server {
     listen localhost:10086;
     location / {
     root /var/www/html/hello/;
     try_files $uri $uri/ =404;
 } }
server {
     listen localhost:10087;
     location / {
      root /var/www/html/nihao/;
     try_files $uri $uri/ =404;
 } }
server {
     listen localhost:10088;
     location / {
     root /var/www/html/huanying/;
     try_files $uri $uri/ =404; }}Copy the code

Generate the corresponding HTML file in the corresponding folder

mkdir -p /var/www/html/hello/
echo '<h1>backend_hello</h1>' > /var/www/html/hello/index.html
mkdir -p /var/www/html/nihao/
echo '<h1>backend_nihao</h1>' > /var/www/html/nihao/index.html
mkdir -p /var/www/html/huanying/
echo '<h1>backend_huanying</h1>' > /var/www/html/huanying/index.html
Copy the code

Reload the configuration file

/usr/sbin/nginx -t
/usr/sbin/nginx -s reload
netstat -tnulp | grep nginx
Copy the code

Result :(default polling mode)

  • First request

  • Second request

  • Third request