0

I've got two web servers running on a machine where one is an application that I don't need to make publuc directly (it's Meilisearch to be specific). Let's say this app is running on port 7700.

The other server is a React static website that make calls to the first one using localhost:7700.

I've made the react web server public using nginx and I can see the website but it fails to communicate with the private server.

What am I doing wrong? Do I need to expose the 7700 to the internet as well?

Milad
  • 4,901
  • 5
  • 32
  • 43
  • As I understand, since it is a static react app, it makes those requests using a javascript running from the remote user browser? If I understand correctly, your only options is to expose that port (or wrap those requests with the nginx under some URI prefix, e.g `/api/...`, then you can avoid exposing the port). – Ivan Shatsky Jan 25 '22 at 22:13
  • When I build this React app I can set an environment variable telling it where the other server is. I set it to localhost:7700 assuming this call happens on the remote (i.e. server) machine. I just tried changing this env to the IP of the remote does indeed fix the problem but I'd prefer not to do that. I guess I can create another nginx reverse proxy for this second server but maybe these URI prefixes is what I need. I have never used them before. – Milad Jan 25 '22 at 22:29
  • I'm a complete noob when it comes to js and React so sorry if I don't quite know what I'm talking about here. – Milad Jan 25 '22 at 22:30
  • 1
    The common approach is to use something like `location / { # main location } location /api/ { proxy_pass http://localhost:7700; }`. This is a __very__ simplified example. – Ivan Shatsky Jan 25 '22 at 22:33
  • that worked perfectly! – Milad Jan 25 '22 at 23:05

0 Answers0