Having an issue with a Netlify proxy

Hey, I’m having an issue with a proxy on Netlify. I’ve read all the docs and the troubleshooting post in this community ( [Support Guide] Making redirects work for you - troubleshooting and debugging ), but I still seem to be having an issue.

Instead of showing the proxy’d url as part of my site, it’s just sending me to the proxy’d url. Here are the details:

I have a react app hosted on Netlify that has the https://gyfteo.com/ domain setup ( loving-payne-8c0665 is the Netlify name ). I want to proxy a wordpress blog ( https://blog.gyfteo.com/ ) to https://gyfteo.com/blog. The proxy seems to partially work, except when I go to https://gyfteo.com/blog, it’s just sending me to https://blog.gyfteo.com/ instead of showing the blog on https://gyfteo.com/blog.

I’m using a netlify.toml file and it is being processed when the react site is deployed to netlify. Here’s the file:

[[redirects]]
  from = "/blog/*"
  to = "https://blog.gyfteo.com/:splat"
  status = 200
  headers = {X-From = "Netlify"}


[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

I had force = true in there but removed it in hopes that would do the trick, but no luck. Any help would be appreciated.

It’s your server that’s sending a 302:

Thus the issue.

Hey @hrishikesh, thanks for the reply. The server is Netlify - any suggestions on what I can update in the netlify.toml file? Or is there another route to look into here?

x-redirect-by and x-turbo-charged-by show the source of the issue. The server is Netlify because you proxied the request. But the source of the redirect is not Netlify, it’s WordPress.

Hey @hrishikesh, right, ya, i’m trying to proxy a wordpress site to Coming Soon – Gyfteo Blog. I’m not following your responses on what the issue is. My understanding of setting up a proxy is that i can make another site show up as a subdirectory of my main domain. Do you know if there is anything I need to change in my netlify.toml file to make this work?

If you intend to proxy to us, we won’t be able to help you as described here:

If you’d like us to proxy to another site, let us know and we can guide you in that configuration.

hey @fool, I think i’m saying it right when i say, yes, i want to proxy to another site. My main site is hosted on Netlify and I want to proxy another site to a sub-directory of my main domain. What is the correct configuration to do this?

Thanks for your time.

Hi, @John_Goodman. The issue is that a proxy just returns the responses from the site you proxy to. The site you proxy to is sending the 302 and we just pass that 302 response along to the client. If you want to fix this, you need to change the behavior of the proxy target.

Here are some examples to clarify. Here is a HTTP response showing the status code returned and the location header (if there is one):

$ curl --compressed -svo /dev/null --stderr - https://www.gyfteo.com/blog/  | egrep '^< (HTTP|location)'
< HTTP/2 302
< location: https://blog.gyfteo.com/coming-soon/

To understand where the 302 originates, let’s look at the redirect rule again:

[[redirects]]
  from = "/blog/*"
  to = "https://blog.gyfteo.com/:splat"
  status = 200
  headers = {X-From = "Netlify"}

The rule above will take a request to this URL below:

  • https://www.gyfteo.com/blog/

and proxy it to this URL:

  • https://blog.gyfteo.com/

Whatever that URL above sends as a response, that is what the HTTP client will receive.

So, let’s test that URL using the same curl example as before so see what response it sends:

$ curl --compressed -svo /dev/null --stderr - 'https://blog.gyfteo.com/'  | egrep '^< (HTTP|location)'
< HTTP/2 302
< location: https://blog.gyfteo.com/coming-soon/

This is the same 302 coming directly from the proxy target.

This is why you get the 302 at Netlify. The 302 is coming from the proxy target itself. All Netlify does (all any proxy does) is just pass along the response of the proxy target to the HTTP client. If you don’t want the 302 sent you need to change that behavior at the proxy target (at blog.gyfteo.com).

If there are other questions about this, please let us know.

2 Likes

Ooooookkk, that explains it. I didn’t realize the site I was proxying had a redirect on. I turned it off and the proxy is working as expected. Thanks for your detailed explanation @luke

1 Like