Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SpringBoot API在NGINX反向代理之后_Java_Nginx_Spring Boot_Cors_Reverse Proxy - Fatal编程技术网

Java SpringBoot API在NGINX反向代理之后

Java SpringBoot API在NGINX反向代理之后,java,nginx,spring-boot,cors,reverse-proxy,Java,Nginx,Spring Boot,Cors,Reverse Proxy,我想在代理之后提供我的Restful API,但我不知道如何将请求重定向到spring启动应用程序,以便可以使用域名访问它 我的spring boot应用程序使用spring boot starter tomcat运行,该应用程序部署良好,我可以在服务器上使用java-jar myApplication.jar进行部署 还可以通过在浏览器上写入来远程访问该应用程序 我使用NGINX(版本:NGINX/1.11.10)作为反向代理。这是我的配置: nginx.conf 网站可用/fakedomai

我想在代理之后提供我的Restful API,但我不知道如何将请求重定向到spring启动应用程序,以便可以使用域名访问它

我的spring boot应用程序使用spring boot starter tomcat运行,该应用程序部署良好,我可以在服务器上使用java-jar myApplication.jar进行部署

还可以通过在浏览器上写入来远程访问该应用程序

我使用NGINX(版本:NGINX/1.11.10)作为反向代理。这是我的配置:

nginx.conf 网站可用/fakedomain.com 服务器响应的状态代码为:301已永久移动。

控制台输出为:

XMLHttpRequest cannot load https://www.fakedomain.com/api/v1/method. Redirect from 'https://www.fakedomain.com/api/v1/method' to 'https://fakedomain.com/api/v1/method' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://fakedomain.com' is therefore not allowed access.

您只需要
proxy\u pass
而不需要
proxy\u redirect

您已在此行上发送重定向:

proxy_redirect          http://1.2.3.4:8090 https://fakedomain.com/;
XMLHttpRequest cannot load https://www.fakedomain.com/api/v1/method. Redirect from 'https://www.fakedomain.com/api/v1/method' to 'https://fakedomain.com/api/v1/method' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://fakedomain.com' is therefore not allowed access.
proxy_redirect          http://1.2.3.4:8090 https://fakedomain.com/;