Nginx-- reverse proxy configuration

Example 1

Achieve results: www.test.com entered in the browser, tomcat jump to the main page.

Under Mac hosts here:

/etc/hosts

Configure ip domain name mapping:
Here Insert Picture Description

Nginx modify configuration files nginx.conf:
Here Insert Picture Description
To listen on port 80, to configure a forwarding path, it is forwarded to the machine tomcat.

Reload Nginx:

sudo nginx -s reload

Start tomcat, in the browser to access www.test.com:

Automatically jump to the tomcat welcome page:
Here Insert Picture Description

Example 2

To achieve the effect: Use Nginx reverse proxy, jump to a different service port in the path of access, Nginx listening port is 9001.

访问http://localhost:9001/edu/ 跳转到127.0.0.1:8080
访问http://localhost:9001/vod/ 跳转到127.0.0.1:8082

Prepare two tomcat:

  • tomcat9 port 8082
  • tomcat8 port 8080

Html prepare two documents:
Tomcat9 in the first place:
webapps / EDU / a.html:
Here Insert Picture Description

In the second tomcat8:
the webapps / VOD / a.html:
Here Insert Picture Description

Nginx modify configuration files nginx.conf:
Here Insert Picture Description

Nginx and started two tomcat:

Browser enter: localhost: 9001 / edu / a.html

Here Insert Picture Description
Browser enter: localhost: 9001 / vod / a.html
Here Insert Picture Description

Published 674 original articles · won praise 1904 · Views 240,000 +

Guess you like

Origin blog.csdn.net/cold___play/article/details/104082163