javaWeb项目,使用Nginx代理后,浏览器跨域问题怎么解决?
我在web项目中集成了v14版本的报表服务,之前由于浏览器跨域问题,已经配置过web.config文件,在测试服务器上已经测试通过了;但是部署到生产服务器上后,这个跨域问题又出现了,之前解决问题的时候这里配置的是我的测试服务器的公网IP,上了生产服务器后使用公网IP就不行了;
测试服务器和生产服务器唯一不同的是生产服务器上使用了Nginx代理,测试服务器上没有,现在我要怎么配置以便解决这个问题呢?
本帖最后由 KearneyKang 于 2020-7-3 17:54 编辑
您好,你参考下这个地址:https://docs.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-3.1
我个人觉得这个更加简洁容易明白:https://stackoverflow.com/questions/17323350/access-control-allow-origin-with-multiple-domains
建议你看看
这是我们研发给的一个解决办法
我看了你那个网址哪里写的是一个固定的网址,然后使用Nginx的网址可能是不固定的,你把哪里换成一个通配符号看看:
add_header 'Access-Control-Allow-Origin' '*'; 本帖最后由 sunnyboom 于 2020-6-19 11:42 编辑
KearneyKang 发表于 2020-6-4 11:28
我看了你那个网址哪里写的是一个固定的网址,然后使用Nginx的网址可能是不固定的,你把哪里换成一个通配符 ...
问题描述:浏览器跨域问题做过的尝试:修改asp.net项目下的web.config文件,在<system.webServer>增加了以下代码: <httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="localhost:8080/TestWeb" />
<add name="Access-Control-Allow-Headers" value="Access-Control-Allow-Headers, Origin,Accept,Expires, X-Requested-With,Cache-Control,Content-Type,Pragma,Access-Control-Request-Method, Access-Control-Request-Headers" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE" />
<add name="Access-Control-Allow-Credentials" value="true" />
</customHeaders>
</httpProtocol>
该办法的处理结果:Access-Control-Allow-Origin标签值“配置具体的IP或域名时”跨域问题是可以被解决的产生的新问题(目前需要解决的问题):因为我现在有一个域名和一个IP需要能够同时访问报表服务,但是上面所示标红的代码不能配置“*”,如下图所示。Access to fetch at 'http://localhost:58720/api/reporting/reports/AcmeStore.rdlx/info' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.
现在我需要怎么做能够让多个IP同时支持跨域访问;下面是我使用的web测试程序,asp.net为咱们示例程序中的“ActiveReportsV14SP1\示例源码\WebSamples14-master\JsViewerSamples\JSViewer_MVC”,您可以跑起来测试一下。<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<appSettings>
<add key="webpages:Version" value="3.0.0.0"/>
<add key="webpages:Enabled" value="false"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5" requestPathInvalidCharacters=""/>
</system.web>
<system.webServer>
<handlers>
<add name="nostaticfile" path="*" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<security>
<requestFiltering allowDoubleEscaping="true"/>
</security>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Access-Control-Allow-Headers, Origin,Accept,Expires, X-Requested-With,Cache-Control,Content-Type,Pragma,Access-Control-Request-Method, Access-Control-Request-Headers" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE" />
<add name="Access-Control-Allow-Credentials" value="true" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
问题收到,我去研究下 KearneyKang 发表于 2020-6-19 16:13
问题收到,我去研究下
好的,谢谢 正在研究,问题已经重现 KearneyKang 发表于 2020-6-22 09:10
正在研究,问题已经重现
您好,这个问题怎么样了,有解决方法么? 你好,我这边试了好几种办法还是不行,现在已经提交给研发团队了。估计还需要 一丢丢时间 KearneyKang 发表于 2020-6-24 09:21
你好,我这边试了好几种办法还是不行,现在已经提交给研发团队了。估计还需要 一丢丢时间
好的
页:
[1]
2