tomcat+nginx domain name configuration method

  • 2020-09-16 07:52:11
  • OfStack

Most of the time we have more than one tomcat per server. How to access a project under tomcat via domain name (without port number) is usually to modify the tomcat port to 80, but there are many tomcat diseases, such as you need to solve the situation of 80 port being occupied, this article will not go into details.

How to use nginx proxy for domain name access

Find nginx conf/nginx conf, key configuration to do the following:


upstream xx{ # configuration upstream The node, in this case the node name is" xx " 
  server 116.255.111.111:8080;
 }
 server{
  listen 80;
  server_name www.xxx.xx; # This configuration nginx Domain name required for proxy 
  location / {
    proxy_pass http://xx; # Specify the reverse proxy for the one configured above upstream Node" xx " 
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
 }

Modify the tomcat server.xml file


<Host name="xxx.xxx.xxx" appBase="webapps" unpackWARs="true" autoDeploy="true">
  <Context path="" docBase="/home/web/xxx" reloadable="true" crossContext="true" />
</Host>

Note in red that name is not available for your domain name path is not available

conclusion


Related articles: