I am trying to make api requests between two local dev sites. I noticed that I can’t connect to one site from another via the WP Rest API (it simply times out and says it cannot connect) but my API request when pasting the url into the browser successfully returns the data.
Then I noticed that both sites are running on port 80. I found a few people asking how to change the port to a custom one however the posts are a few years old and include broken links to documentation.
Setting ansible_port in the hosts file is for using a non-standard port to connect to the server over SSH and is unrelated to anything with the webserver.
Based on your post, I’m not seeing why you would need to be modifying the webserver ports. If you provide more details/show some code, then maybe someone can chime in with suggestions on how to fix your REST API connection issues.
What’s strange is that request goes through when made to the remote staging server of website A from the dev site of website B.
Also, when I purposely input the wrong url for the REST API, I am able to properly handle the exception.
It’s only when I make the request to the dev site of Website A that it times out and provides no chance to handle the exception.
Here is the error it produces:
# cURL error 7: Failed to connect mysite.test port 80 after 65058 ms: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://mysite.test/wp-json/wp/v2/data_publications?include=17793
And when I copy the url mentioned in the error and simply paste it into my browser or curl it, it returns a proper response.
So that’s what led me to think that having both sites running on the same port and making requests to each other could be jamming things up, but I’ll admit I don’t really understand what happens within a port.
Here is my truncated with() function from my composer (note I am using Guzzle for the http request):