I'm having trouble setting up a reverse proxy environment so that WordPress is accessible from https://www.example.com/blog
(.net server) which delegates the processing of the request to https://blog.example.com
(running apache).
I believe everything is set up correctly, however there are some peculiarities that are occurring with WordPress: incorrect redirects after submitting forms in admin portal, pagination in admin portal directing to the subdomain, etc. It appears that WordPress occasionally generates links using the Host header, and I think this is probably what is causing the issues above. Perhaps WordPress is incorrectly seeing the Host header as blog.example.com
instead of www.example.com
?
Sure enough, when I use the following code to output the headers that WordPress sees to HTML comments, Host is blog.example.com
when I visit https://www.example.com/blog
:
<?php
$headers = getallheaders();
foreach($headers as $key=>$val){ ?>
<!--<?php echo $key . ': ' . $val . '\n';?>-->
<?php } ?>
The strange thing is, when you make a cURL request, the response appears to indicate the Host from that client is www.example.com
, as is expected:
$ cURL -v www.example.com/blog
* Trying 123.45.6.78:80...
* Connected to www.example.com (123.45.6.78) port 80 (#0)
> GET /blog HTTP/1.1
> Host: www.example.com
> User-Agent: curl/7.83.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Mon, 10 Apr 2023 21:35:09 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Set-Cookie: ARRAffinity=edad4441c23080036d9f0536b216416688fe1dedbf252eab20f9ce201c265bd6;Path=/;HttpOnly;Domain=www.example.com
< Vary: Accept-Encoding
< Link: <https://www.example.com/blog/wp-json/>; rel="https://api.w.org/"
< Link: <https://www.example.com/blog/wp-json/wp/v2/pages/5>; rel="alternate"; type="application/json"
< Link: <https://www.example.com/blog/>; rel=shortlink
< X-Cache-NxAccel: BYPASS
< X-Powered-By: ARR/3.0
< X-Powered-By: ASP.NET
< CF-Cache-Status: DYNAMIC
< Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=%2B5N8KX8LJX7YfunVpgH70C8yKlW7qISgnAJNnoLS%2FfSUbTWLMvKwlpm8KzUkWgSMyZO6dDYa%2BgoPp0%2BtlkUbxm6%2F%2BAI7QRRObCBaijDvpRcHLIcl%2FWrIdvqyptwF5QoogmRFnJHg"}],"group":"cf-nel","max_age":604800}
< NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
< Server: cloudflare
< CF-RAY: 7b5e1e2bd826ee96-AKL
<
< {snipped html}
<
* Connection #0 to host www.example.com left intact
So cURL is seeing one Host header, and WordPress another. I have disabled all WordPress plugins, purged the Cloudflare cache, disabled WordPress cache and reverted to the standard 2023 WordPress theme, but the issue remains. I have also attempted to overwrite the Host header in wp_config.php, but this caused an infinite redirect.
The infinite redirect (and past experience) makes me think that this is a web host issue, but they're not being too much help. They offer Managed WordPress installations, so I don't have much visibility of their server infrastructure. Any thoughts on what could cause these peculiarities, or do you agree that this is likely a web host issue?