使用nginx http代理使用子域的REST风格的API调用

我已经将godaddy子域名backend.example.com和app.example.com转发给Google Compute Engine的相同公开IP XXX.XXX.XXX.XXX。 我configuration了nginx webserver,并且我的springboot后端正在端口8090上运行。目前使用以下configuration –

server { listen 80; gzip on; server_name backend.example.com; location / { root html/example; index index.html; } location /private { proxy_pass https://127.0.0.1:8090; } location ~* \.(gif|jpg|jpeg|png|js|css)$ { } } 

我的networking应用程序工作正常。 但是REST风格的api调用只在url是http://XXX.XXX.XXX.XXX/api/view时才起作用 。 当使用http://backend.example.com/api/view作为url时,获取下面的html响应

  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Backend</title> <META name="description" content="Backend"> </head> <frameset rows="100%,*" border="0"> <frame src="http://XXX.XXX.XXX.XXX" frameborder="0" /> <frame frameborder="0" noresize /> </frameset> <!-- pageok --> <!-- 12 --> <!-- --> </html> 

我希望JSON响应可以像在XXX.XXX.XXX.XXX/api/view中发生的那样在backend.example.com/api/view中提供。 我已经在nginxconfiguration文件中尝试了许多不同的configuration设置,但没有任何工作。 需要一些build议如何解决这个问题。

所以经过几天的尝试,我偶然发现了一个解决scheme。

将没有屏蔽的子域转发到IP地址,并在Google Cloud DNS中创build一个DNS区域。 在Cloud DNS中input子域名的logging。 复制提供的自定义名称服务器并粘贴到您的域名托pipe网站名称服务器logging。 这么多工作就像魅力。