After configuring nginx + Tomcat, add the project to webapps. CSS and JS cannot access the homepage, leading to an error in homepage layout. After carefully analyzing the cause, we found that the CSS and JS addresses were obtained by basepath. Basepath is defined as follows:
String basepath = request. getscheme () + request. getservername () + request. getserverport () + path;
Where
1. Request. getscheme () returns the Protocol Name HTTP, which is combined with the following ": //" to form http: // 2, request. getservername (): get the name of your server. 3. Request. getserverport () is used to obtain the service port number.
I defined a virtual IP address in nginx, but it was like this:
Upstream test {server 192.168.232.129: 8080 Weight = 1; server 192.168.232.130: 8080 Weight = 1; server 192.168.232.135: 8080 Weight = 1 ;}
However, accessing CSS in this way leads to the following address: http: // test/project name/.....css. Because it is directed to the domain name, the domain name does not exist during the test, so it is changed to the following method:
Upstream 192.168.232.140 {server 192.168.232.129: 8080 Weight = 1; server 192.168.232.130: 8080 Weight = 1; server 192.168.232.135: 8080 Weight = 1 ;}
The above changes can meet the access requirements, but the actual IP address is exposed, http: // 192.168.232.140/project name/.....css. Therefore, in the actual environment, you need to change to a domain name.