まず、ダウンタイムの問題解決
Tomcatのハング(サーバーがダウンしている)のいずれかが、その後、見つける別のサーバーが実行され続け2 Tomcatを、準備
1、アナログ停電
2、nginxのリスタートnginx.confファイルを変更
図3に示すように、正常な応答
4、アナログダウンタイムの問題は、再び次のスタンバイサーバが実行し続けわかります
第二に、クロスドメインの問題解決
:nginxのは、実装は、クロスドメインの問題を解決
www.a.com:8080/aが
www.b.com:8081/b
、そのソリューションは、AJAXリクエストがエンジニアリングbでページに直接送信されている場合、問題が発生したクロスドメインであります: nginxのに同じ時間エージェントのAとB、nginxの要求のルーティングを行う、nginxのBプロジェクトのページへの直接の直接アクセス
1、ショーディレクトリ
2、輸入依存関係
3、NginxServlet
package com.a; 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 { //1、接收数据 String username = request.getParameter("username"); System.out.println("接收的数据:"+username); //2、响应结果 response.getWriter().write("success"); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } }
4、index.jsp
<%-- Created by IntelliJ IDEA. User: zheng Date: 2020/2/10 Time: 15:01 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Nginx解决跨域问题</title> <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script> <script> $(function () { $("#button").click(function () { $.ajax({ url:"http://www.znzn.com/A/NginxServlet?username="+$("#username").val(), type:"GET", success:function (result) { alert(result); } }) }); }) </script> </head> <body> 数据:<input type="text" name="username" id="username"/> <input type="button" id="button" value="请求"/> </body> </html>
5、修改nginx.conf文件、重启Nginx
6、效果展示