Nginx reverse proxy learning example tutorial

Nginx reverse proxy learning example tutorial

1. Reverse proxy preparation

1. Install Tomcat in Linux system

Unzip tomcat to /usr/src. The jdk environment is required to start. If you don't have a jdk environment, install it. My centos7 comes with jdk1.8.

Please add a description of the image

2. Start tomcat

Enter the bin directory of tomcat, there is a startup.sh file.

Please add a description of the image

./startup.sh starts the tomcat server

Please add a description of the image

3. Ports open to external access

View currently open port numbers

firewall-cmd --list-all

Set the open port number

firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --add-port=8080/tcp --permanent

Restart the firewall

firewall-cmd --reload

4. Test access to tomcat

http://192.168.1.173:8080/

Please add a description of the image

The preliminary preparations are now complete!!

2. Reverse proxy case (I)

1. Achieve results

Open the browser, enter www.123.com in the browser address bar, and jump to the Linux system tomcat page

Please add a description of the image

2. Specific configuration

Step 1: Add to the local /etc/hosts file

Please add a description of the image

The second step is to configure request forwarding in nginx (reverse proxy configuration)

cd /usr/local/nginx/conf
vim nginx.conf

Modify and add some content

Please add a description of the image

3. Testing

Visit www.123.com

Please add a description of the image

Access tomcat by accessing nginx's ip, success! ! ! !

2. Reverse proxy case (II)

Achieve results

Use nginx reverse proxy to jump to services on different ports according to the access path. The nginx listening port is 9001.

  • Visit http://192.168.1.173/edu/ and jump directly to 192.168.1.173:8080
  • Visit http://192.168.1.173:9001/vod/ and jump directly to 192.168.1.173:8081

1. Preparation

(1) Prepare two tomcat servers, one with port 8080 and one with port 8081

(2) Create two folders, put the compressed packages of Tomcat in each folder, decompress them, and then modify the server.xml file in the conf file of one of the Tomcat files and change the port to 8081.

(3) Create edu and vod folders under the webapps file, and create an a.html test page in the folder to display the port number.

2. Specific configuration

(1) Find the nginx configuration file and configure the reverse proxy

Please add a description of the image

(2) Open ports for external access: 9001 8080 8081

location directive description

This directive is used to match URLs

The syntax is as follows:

location [ = | ~ | ~* | ^~] uri {

}

1. =: used before a URI that does not contain a regular expression, requiring the request string to strictly match the URI. If they match

If successful, stop searching further and process the request immediately.

2. ~: Used to indicate that the URI contains a regular expression and is case-sensitive.

3. ~*: used to indicate that the URI contains a regular expression and is case insensitive.

4. ^~: used before the URI without regular expression, requiring the Nginx server to find the identifier URI and the request string

After the location with the highest string matching degree is found, the request is processed immediately using this location instead of the location

The regular uri in the block is matched against the request string.

Note: If the uri contains a regular expression, the ~ or ~ sign must be present . *

Final Test

Please add a description of the imagePlease add a description of the image

Summarize

This is the end of this article about Nginx reverse proxy learning. For more relevant Nginx reverse proxy 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:
  • Nginx reverse proxy solves cross-domain problems in various situations
  • Nginx routing forwarding and reverse proxy location configuration implementation
  • Implementation of Nginx Intranet Standalone Reverse Proxy
  • Getting Started with Nginx Reverse Proxy
  • nginx reverse proxy and detailed usage

<<:  A brief discussion on the difference between MYSQL primary key constraint and unique constraint

>>:  How to set the select to be read-only and not editable and the select value to be passable

Recommend

The difference between html empty link href="#" and href="javascript:void(0)"

# contains a location information. The default anc...

Differences between this keyword in NodeJS and browsers

Preface Anyone who has learned JavaScript must be...

How to solve the DOS window garbled problem in MySQL

The garbled code problem is as follows: The reaso...

Solution to the welcome to emergency mode message when booting CentOS7.4

Today I used a virtual machine to do an experimen...

Several practical scenarios for implementing the replace function in MySQL

REPLACE Syntax REPLACE(String,from_str,to_str) Th...

translate(-50%,-50%) in CSS achieves horizontal and vertical centering effect

translate(-50%,-50%) attributes: Move it up and l...

Detailed explanation of Mencached cache configuration based on Nginx

Introduction Memcached is a distributed caching s...

Detailed explanation of Tomcat's Server Options

1. Configuration By default, the first two are no...

Implementation steps for docker-compose to deploy etcd cluster

Table of contents Write docker-compose.yml Run do...

Summary of some points to note when registering Tomcat as a service

Here are some points to note when registering Tom...

Example code for implementing anti-shake in Vue

Anti-shake: Prevent repeated clicks from triggeri...