Exposing external JSON API in an Nginx custom path?

Francis Daly francis at daoine.org
Sun Nov 11 20:36:03 UTC 2018


On Sun, Nov 11, 2018 at 03:55:06PM +0000, Moorage via nginx wrote:

Hi there,

> 	curl -i http://mesh.example.com:8080
> 		HTTP/1.1 302 Found
> 		Location: /mesh-ui/
> 		Content-Length: 0
> 
> I want to expose that UI at an Nginx site custom path.
> 
> 	https://example.com/mesh

So you want the request to nginx of "/mesh/" to become a request to your
upstream server of "/"?

It can be done; however, I suggest that you will find things easier
to reverse-proxy if you can configure the mesh server to expect that
its root is /mesh/, so that it exposes its api at /mesh/api/v1 and it
redirects to /mesh/mesh-ui/

> 		location ~ /mesh/ {

"~" is not "starts with". You probably want "^~" there instead.

> 			proxy_pass http://meshproxy;

If you want the request to upstream to be "/mesh/", use that. Otherwise, use

  proxy_pass http://meshproxy/;

> 			proxy_redirect off;

You probably do not want that. Perhaps "proxy_redirect default;"; perhaps
something else based on whatever the mesh service actually returns. From
your example, you may want

  proxy_pass / /mesh/;

Good luck with it,

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list