nginx to solve the home jump problem

  • 2020-05-12 06:59:22
  • OfStack

nginx and tomcat load balancing

For example, www.csdn.NET has two tomcat behind it.

Configure load balancing:


upstream csdn-tomcat{
  server 192.168.100.101:8080;
  server 192.168.100.102:8080;
}
server {
 listen 80;
 server_name www.csdn.net csdn.net;
 index index.html;
 location / {
  if ( $request_uri = "/" ) {
    rewrite "/" http://www.csdn.net/index.html break;
  }
  proxy_pass http://csdn-tomcat$request_uri;
 }
 # 301 redirect:
 location /blog/index.html {
  return 301 http://www.iteye.com$request_uri;
 }
}

After a lot of research, we finally solved the problem.

First, assume that the top of the home page is a static html.

A 301 jump occurs when the user does not enter www.csdn.Net directly.

Guide users to www. csdn. net/index html home page.

Other dynamic requests hit tomcat.

This makes a 301 jump directly above nginx.

This solves the problem because tomcat is made with spring.

The suffix is.html. There is no way to distinguish tomcat from normal html.

It would have been easier if the suffix tomcat had been.do.

Mainly to relieve the pressure of tomcat. Leave html css image to nginx.

But the on-line time is more troublesome, separately on-line.

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: