(5) Nginx configuration example 2 reverse proxy

 

1. The effect:

  Use Nginx reverse proxy, jump to different port services according to the access path, Nginx listening port is 9001

  1. Visit http://127.0.0.1:9001/bs-manager/ to jump directly to 127.0.0.1:8001
  2. Visit http://127.0.0.1:9001/bs-webapp/ to jump directly to 127.0.0.1:8002

2. Preparation

  1. Prepare two tomcat servers, one port 8001 and one port 8002.
  • Edit the file using the command: /conf/server.xml file  vim server.xml
  •  The revised version is as follows:

1. Modify the default port of the server from 8005-> 8091 by default

å¨è¿éæå ¥ å¾çæè¿ ° 

2. Modify the default port of http protocol, from the default 8080-> 8082

å¨è¿éæå ¥ å¾çæè¿ °

3. Modify the default port of the default ajp protocol from the default 8009-> 9001

å¨è¿éæå ¥ å¾çæè¿ °

  1. tomcat8.5 modify the port number     at the start command bin directory   ./startup.sh
  2. Start Tomcat on Linux, the result pops up: -bash: ./startup.sh: Permission denied prompt, solution
用命令chmod 修改一下bin目录下的.sh权限就可以了 
chmod u+x *.sh 
这里的u 这里指文件所有者,+x 添加可执行权限,*.sh表示所有的sh文件。

  4. Test page: (Precondition: The server needs to open the firewall or the corresponding port number)

          IP: 8001 pass, IP: 8002 pass ( Online server needs to wait about 5 minutes to pass )

Three, concrete arrangement

  1. Prepare test page ( link for preview )

    2. Modify the Nginx configuration

     Modify the configuration file of nginx Add server {} in the http block to
     modify the comments.

     å¨è¿éæå ¥ å¾çæè¿ °

After successful modification

    å¨è¿éæå ¥ å¾çæè¿ °

  • Developed ports: nginx listening port: 9001, tomcat8001 port: 8001, tomcat8002 port: 8002.
  • The test result    test.wxw.plus represents your server IP

Summary: The location directive indicates that  this directive is used to match URLs.

  • The syntax is as follows:
  1.  = : Before being used for uri without regular expression, the request string must be strictly matched with uri. If the match is successful, stop searching downward and process the request immediately.
  2.  ~ : Used to indicate that uri contains regular expressions and is case sensitive.
  3.  ~ * : Used to indicate that uri contains regular expressions and is not case sensitive.
  4. ^ ~ : Before being used for URIs without regular expressions, the Nginx server is required to find the location with the highest matching between the uri and the request string, and then use this location to process the request, instead of using the regular uri and request in the location block String matching.

Note: If uri contains a regular expression, it must have a ~ or ~ * mark.

 

Published 108 original articles · Like 58 · Visits 50,000+

Guess you like

Origin blog.csdn.net/qq_41893274/article/details/104697274