Nginx+Tomcat single IP multi domain multi site access

  • 2020-05-13 04:42:25
  • OfStack

Implementation of Nginx+Tomcat single IP, multi-domain, multi-site access

Preface:

Help a friend recently made two website, tiny budget. Little to the two sites can only run on 1 512 M memory public server (tomcat + MySQL, because memory is too small, can only put the two site deployed on the same 1 tomcat), each web site have their own domain name, preliminary consideration make nginx do reverse proxy, the two domain names mapped to the corresponding applications. Hence the configuration problem with the title "nginx multi-domain list server single IP single Tomcat different applications". Without further ado, Nginx will post the configuration file here for your reference:

The configuration file for the domain name A: www.a.com is as follows:


server { 
  listen    80; 
  server_name *.a.com; 
  location / { 
    proxy_pass http://localhost:8080/projectA/; 
    proxy_set_header  Host  $host; 
    proxy_set_header  X-Real-IP  $remote_addr; 
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for; 
  } 
} 

The configuration file for the domain name B: www.b.com is as follows:


server { 
  listen    80; 
  server_name *.b.com; 
  location / { 
    proxy_pass http://localhost:8080/projectB/; 
    proxy_set_header  Host  $host; 
    proxy_set_header  X-Real-IP  $remote_addr; 
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for; 
  } 
} 

The above is Nginx+Tomcat single IP, multi-domain, multi-site access to the example, if you have questions please leave a message or to the site community to exchange discussion, thank you for reading, hope to help you, thank you for your support to the site!


Related articles: