nginx解决前端调用后端接口跨域问题

(1) nginx配置文件

server {
        listen 8886;                           【8886是前端项目在nginx下的监听端口】
        server_name  127.0.0.1;
        
        location /{
            proxy_pass http://127.0.0.1:8083/YZT3.0/;            【8083是前端项目在tomcat下对应的端口】
        }
        location /hmyj{
            proxy_pass http://服务器ip地址:9021/hmyj;
        }
    }
    server {
        listen 8887;                           【8887是前端项目在nginx下的监听端口】
        server_name  127.0.0.1;
        
        location /{
            proxy_pass http://127.0.0.1:8083/zjgIM/;        【8083是前端项目在tomcat下对应的端口】
  } location /zjgyj{ proxy_pass http://服务器ip地址:19099/zjgyj;  } }

(2) 调用时的写法


url: "/zjgyj/zbzsfacade/queryRecentlyList",

 (3) 启动nginx

start nginx
./nginx -t
./nginx -s reload

 (4) 启动tomcat

posted @ 2020-12-24 15:04  _0123456789  阅读(969)  评论(0编辑  收藏  举报