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

Zabbix's psk encryption combined with zabbix_get value

Since Zabbix version 3.0, it has supported encryp...

Solution to Linux QT Kit missing and Version empty problem

Currently encountering such a problem My situatio...

Implementation of element input box automatically getting focus

When making a form in a recent project, I need to...

Summary of methods for querying MySQL user permissions

Introduce two methods to view MySQL user permissi...

CentOS 7.6 installation of MySQL 5.7 GA version tutorial diagram

Table of contents Environment Preparation Environ...

Implement QR code scanning function through Vue

hint This plug-in can only be accessed under the ...

How to view the storage location of MySQL data files

We may have a question: After we install MySQL lo...

Tips for organizing strings in Linux

In Linux operations, we often replace and count s...

Differences between ES6 inheritance and ES5 inheritance in js

Table of contents Inheritance ES5 prototype inher...

Specific usage instructions for mysql-joins

Table of contents Join syntax: 1. InnerJOIN: (Inn...

React Diff Principle In-depth Analysis

Table of contents Diffing Algorithm Layer-by-laye...

Getting Started: A brief introduction to HTML's basic tags and attributes

HTML is made up of tags and attributes, which are...

Vue custom table column implementation process record

Table of contents Preface Rendering setTable comp...