I’m configuring reverse proxy server with nginx
Nginx.conf file is like this, location / -> front server address, location /api -> api server address.
Front server fetch from http://${api_addr}/api
originally(before setting nginx), but now I changed api URL to http://${nginx_addr}/api
for constructing reverse proxy server. I am wondering if it is correct to send the request directly from the front to the api address or if it is correct to send the request to the nginx address?
2
Answers
It is best practice to always query the Nginx endpoint and not the specific port. By directly querying the specific api port, you are completely bypassing the server routing service and could therefore accidentally overload your api endpoint if not careful.
By routing everything through the Nginx server, you ensure that your api service remains healthy and works as expected.
So you’re configuring a website and you want it to direct traffic to your frontend (html etc) and have an api route going to your api, if I’m reading that correctly?
You’d do it similar to this
The variables stop nginx hitting an ’emerg’ (fatal error) if a host falls down in the background between reloads; it can also be helpful with services where the frontend has a large IP range like cloudfront etc.
In the case of your frontend if you’re calling something like CloudFront you’d need to force TLS1.2
X-Forwarded-Proto https
is needed if the backend app is returning paths (.net apps use this to set paths to https etc)Its best to proxy all your requests for an application via the same site config for multiple reasons, such as…
If you provide a bit more info I can probably pad this out