How to implement Nginx reverse proxy for multiple servers

How to implement Nginx reverse proxy for multiple servers

Nginx reverse proxy multiple servers, which means that when we initiate different requests to nginx, nginx will forward them to different servers according to the different requests. As shown in the figure below, when we access resource a through port 8000, nginx will forward the request to server 8080, and when accessing resource b, it will forward it to server 8081.

Let's do some preparation first. First, prepare two tomcat servers, port 8080 and port 8081. Port 8080 is the default. Here we modify port 8081. First, we go to the conf directory under tomcat, enter the server.xml file and make the following two changes:

1. Change the shutdown port number to 8015

2. Change the start port number to 8081

Now we have two tomcats. Next, we start the two tomcats to see if they can be accessed. If not, it may be a problem with your firewall. systemctl stop firewalld can shut down the firewall. If still not accessible, it may be that Alibaba Cloud has not opened the port.

When your tomcat can be accessed normally, we deploy resource a on server 8080 and resource b on server 8081. The specific deployment is to create directories a and b respectively in the webapps directory under tomcat, and create index.html, write 8080 and 8081 respectively in it, for the convenience of testing later. Here is resource a

OK, the next step is to configure nginx. Go to the conf directory of nginx, open the nginx.conf file, and manually configure a server block

The server means:

  • listen 8000: listen to port 8000, which is the nginx port we directly access
  • server_name localhost: is the domain name
  • location ~ /a/: all requests to access resource a will be forwarded through the following proxy
  • http://39.106.231.3:8080; means the proxy forwards to the 8080 server under the host with the IP address 39.106.231.3

After configuration, execute ./nginx -s reload in the sbin directory to reload the configuration file.

Access: 39.106.231.3:8000/a

Access: 39.106.231.3:8000/b

This is the end of this article about how to implement Nginx reverse proxy for multiple servers. For more relevant Nginx reverse proxy server content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Explanation of nginx load balancing and reverse proxy
  • Getting Started with Nginx Reverse Proxy
  • Nginx reverse proxy configuration to remove prefix case tutorial
  • Full process record of Nginx reverse proxy configuration
  • About nginx to implement jira reverse proxy

<<:  Select web page drop-down list and div layer covering problem

>>:  In-depth understanding of the use of r2dbc in MySQL

Recommend

Detailed explanation of the process of installing msf on Linux system

Or write down the installation process yourself! ...

Tutorial on installing and uninstalling python3 under Centos7

1. Install Python 3 1. Install dependency package...

How to generate a free certificate using openssl

1: What is openssl? What is its function? What is...

How to install setup.py program in linux

First execute the command: [root@mini61 setuptool...

Linux uses iptables to limit multiple IPs from accessing your server

Preface In the Linux kernel, netfilter is a subsy...

Memcached method for building cache server

Preface Many web applications store data in a rel...

Learn how to use the supervisor watchdog in 3 minutes

Software and hardware environment centos7.6.1810 ...

CSS code to achieve 10 modern layouts

Preface I watched web.dev's 2020 three-day li...

How to remotely connect to the cloud server database using Navicat

It is very convenient to connect to a remote serv...

JavaScript programming through Matlab centroid algorithm positioning learning

Table of contents Matlab Centroid Algorithm As a ...

Examples of vertical grid and progressive line spacing

New Questions Come and go in a hurry. It has been...

Use HTML and CSS to create your own warm man "Dabai"

The final result is like this, isn’t it cute… PS:...

Summary of the execution issues between mysql max and where

Execution problem between mysql max and where Exe...