Nginx负载均衡设置(2)

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/NginxServlet")
public class NginxServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Nginx负载均衡!");
        System.out.println("当前访问端口:"+request.getServerPort());
    }

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}

2、修改nginx.conf文件

  

Nginx负载均衡设置

 3、启动Nginx和Tomcat  4、访问   5、控制台效果  无论访问几次都只会在80端输出

   

Nginx负载均衡设置

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/0f7fed62e559e8bde8de2d6f5bb3186d.html