Report this

What is the reason for this report?

Reverse proxied web app not making api call from the location

Posted on March 30, 2020
Gordon Pham-Nguyen

By Gordon Pham-Nguyen

Software Engineering Student

I have two web apps running on my home server, one on port 7001 and the other on port 3578.

Both of these apps have some REST API routes, that all start with /api.

My NGINX config is as follows for the two locations blocks:

location /deals/ {
	include /config/nginx/proxy.conf;
	proxy_cache_bypass $http_upgrade;
	proxy_pass http://192.168.1.65:7001/;
	proxy_redirect off;
	proxy_set_header Connection "upgrade";
	proxy_set_header Host $host;
	proxy_set_header Upgrade $http_upgrade;
	proxy_set_header X-Forwarded-Host $host;
	proxy_set_header X-Forwarded-Proto https;
	proxy_set_header X-Real-IP $remote_addr;
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	proxy_set_header X-Forwarded-Server $host;
}

location /speed/ {
	include /config/nginx/proxy.conf;
	proxy_cache_bypass $http_upgrade;
	proxy_pass http://192.168.1.65:3578/;
	proxy_redirect off;
	proxy_set_header Connection "upgrade";
	proxy_set_header Host $host;
	proxy_set_header Upgrade $http_upgrade;
	proxy_set_header X-Forwarded-Host $host;
	proxy_set_header X-Forwarded-Proto https;
	proxy_set_header X-Real-IP $remote_addr;
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	proxy_set_header X-Forwarded-Server $host;
}

This is the result of a whole afternoon of Googling and searching around…

192.168.1.65 is the local network IP address of my home server.

The problem that I am facing is that when those web apps make api calls, they aren’t making the calls relative to their (new proxied) locations, but rather from the domain url.

When I navigate to https://my-domain.com/deals and https://my-domain.com/speed, I can see my web apps respectively.

BUT the data is never loaded because they are both calling my-domain.com/api instead of my-domain.com/deals/api or my-domain.com/speed/api. I can see this in the network tab of Chrome dev tools, both return 404s.

When I navigate to 192.168.1.65:7001, I can see my web apps and the data loaded correctly.

When I type in manually in the address bar https://my-domain.com/speed/api/example, I can see that it can answer correctly the GET request with a 200 status code.

How can I make them make the calls from their respective locations?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.