New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
How to proxy api call through another domain?
hades_corps
Member
in Help
So, here is my issue: api.domain1.com only respond to certain IPs. But I need to request it from another location. Is there a way to accomplish something like this:
- Request is send to https://api.domain2.com/getdata?a=10 that I own.
- Request is proxy to https://api.domain1.com/getdata?a=10
- Respond data is passed through (text only).
- Domain1 have no idea that the call is from domain2, it think the allowed IP request api.domain1 directly.
I am using CloudPanel which is NGINX based. I am open to the idea using Caddy as well.
Comments
I've done something similar by using Bunny CDN as a proxy
With NGINX or Caddy, you can configure a reverse proxy to forward requests from your domain2 to api.domain1 while preserving the source IP address. This way, api.domain1 will receive the request as if it's coming directly from an allowed IP address.
Here's a high-level overview of how you could set this up:
Configure NGINX or Caddy on your server to act as a reverse proxy.
Set up a proxy pass directive in your NGINX or Caddy configuration to forward requests from your domain2 to api.domain1.
Ensure that the proxy pass preserves the original source IP address in the forwarded request.
Test the setup to ensure that requests from domain2 are successfully proxied to api.domain1 without api.domain1 being aware of the origin.
Keep in mind that setting up a reverse proxy requires careful configuration to ensure security and proper functioning. You may need to consult the documentation for NGINX or Caddy and possibly seek assistance from experienced developers or sysadmins if you're not familiar with these technologies.
I would use HAProxy a just insert one backend server in the configuration file.
Basic HAProxy configuration example: https://www.howtoforge.com/how-to-install-haproxy-on-debian-11/#configure-haproxy
Docs: http://docs.haproxy.org/2.9/configuration.html