Hey everyone! I'm looking to configure Nginx to work between my backend and frontend applications, which are running on separate servers. I've found a lot of tutorials online, but most of them focus on setups where everything is on the same machine. I'm pretty lost on how to proceed with the separate server setup. Just for context, my backend is running on FastAPI and my frontend is using NextJS. Both parts are also containerized with Docker. Any guidance or tips for a proper setup would be really appreciated!
2 Answers
It sounds like you want to serve your frontend and backend under the same domain, right? If that’s the case, you’ll need to set up Nginx as a reverse proxy using the `proxy_pass` directive. The cool thing is that the proxy target can be just a URL, so it doesn't matter if it's on localhost or a different server. Just keep in mind that trying to reach over a network can be slower than using localhost, though!
Exactly, `proxy_pass` is the key here. You can even set rules based on the URL to direct traffic appropriately.
Just a heads up, you don't 'integrate' Nginx as you might think. It's a web server that hosts resources and can act as a reverse proxy. For your backend, you would create a container for it (like your FastAPI app), deploy it, and then use its URL for your frontend. Do the same for the frontend, and you'll end up with two separate services that can communicate as needed!
Got it! So I'd have a URL like www.example.com/api for the backend and www.example.com for the frontend? Just confirming that I'm understanding correctly.

Yes, that's exactly what I want to do! Thanks for clarifying that. I'll definitely check out the proxy_pass setup.