In previous articles, we introduced Tomcat single-server deployment, multiple applications and Nginx load balancing: Common policy configuration and parameter knowledge. This article will build the Nginx+Tomcat cluster based on the previous learning.

Download nginx(The installation and use of Homebrew on Mac, start, reload are introduced), and start, enter in the browserlocalhostEnter:

Nginx uses port 80 by default. If you have IIS installed, stop and make sure port 80 is available.

Configure nginx.conf

  • Open the /e t c/nginx/nginx.conf configuration file (not using brew installation may be different from my path)
  • Added under the HTTP nodeinclude vhost/*.conf: Actually, we cannginx.confHowever, in the actual working environment, many ports need to be configured, so that the ports are removed for later maintenance.
  • Create the address to be configured in the vhost(config to nginx.conf) folderizou.work.conf(use the suffix.conf) :
upstream www.izou.work{ server www.izou.work:8080 weight=1; server www.izou.work:9080 weight=1; } server{ listen 80; autoindex on; server_name izou.work www.izou.work index index.html index.htm index.jsp index.php; location / { proxy_pass http://www.izou.work; }}Copy the code

Upstream: While visiting www.izou.work, port 8080 and port 9080 are weighted the same. Here I’m configuring hosts to map www.izou.work to my local localhost(127.0.0.1). server:

  1. Listen Listens to port 80
  2. Autoindex Automatically generates an index
  3. Server_name Specifies the domain name to access.
  4. index index.html index.htm index.jsp index.phpIndex file loading sequence
  5. Location –proxy_pass: point to the location

Reload nginx and access the domain name in your browserizou.work:

As you can see, nginx points directly to the ports we set up, and ports 8080 and 9080 are accessed with the same frequency as the weights set up, so a simple nginx +Tomca cluster is set up