0%

Nginx

nginx

后台不修改的情况下前端跨域问题

nginx 反向代理

原理

upload successful

浏览器访问nginx入口,nigx代理到实际前端页面,前端想访问跨域资源时访问nginx代理,这样对用户浏览器来说一直都是nginx端口,所以不会产生跨域。

配置

前端web iframe访问跨域

<iframe id='svg-show' name='svg-show' src="http://localhost:8981/api/tumo/svgOperator.jsp?fileId=123123" class="layui-col-md12" style="height: 600px"></iframe>

使用intellij 内置jetty启动

upload successful

后端接口:http://localhost:8080/pssc_service_graph/tumo/svgOperator.jsp?fileId=F92F43DD-36C0-4AB4-A5E9-A5D4821D784C

nginx配置:

1
2
3
4
5
6
7
8
9
10
11
12
server{
listen 8981;
server_name localhost;

location /{
proxy_pass http://localhost:63342;
}

location /api{
proxy_pass http://localhost:8080/pssc_service_graph;
}
}

Welcome to my other publishing channels