Reputation: 81
I have a wordpress official container with a dock port 80 mapped to 32795 external... when I go to administration area of wordpress I get this error:
Important: HTTP Loopback Connections are not enabled on this server. If you need to contact your web host, tell them that when PHP tries to connect back to the site at the URL http://localhost:32795/wp-admin/admin-ajax.php
and it gets the error cURL error 7: Failed to connect to localhost port 32795: Connection refused
. There may be a problem with the server configuration (eg local DNS problems, mod_security, etc) preventing connections from working properly.
I think the problem is that the site inside the container tries to communicate with the 32795 port instead of 80, but it can not because this door is only seen from the outside of the container...
I created a script inside the site with phpinfo, and I checked the loopback connections are on...
There is a solution for this? I have docker un windows with kitematic
thanks
Upvotes: 2
Views: 5706
Reputation: 33
I encountered something similar on MacOS trying to install a Bitnami WP/MariaDB deployment using their docker-compose.yml. I installed a theme using AJAX and while installing, it gave me the same warning. To resolve this with docker-compose you should edit your service and add
extra_hosts:
- "localhost:172.17.0.1"
I think it's because it's the gateway's static IP of docker's bridge
network.
Upvotes: 0
Reputation: 199
I had a similar problem running WordPress with Nginx on Docker Desktop for Windows. I needed to add an entry to the container's hosts
file that directed my local.example.com
domain to hit my ingress-nginx controller so that WordPress' loopback requests would work. Although my setup might be slightly different this might help you.
Open /Windows/System32/drivers/etc/hosts
and copy the IP address that's next to host.docker.internal
. Add an entry to the container's hosts
file on startup that ties the domain to the hosts IP by doing one of the following. IP
is what you copied from your machine's hosts file by host.docker.internal
Docker argument:
--add-host="local.example.com:IP"
Docker compose:
extra_hosts:
- "local.example.com:IP"
Kubernetes:
hostAliases:
- ip: "IP"
hostnames:
- "local.example.com"
Upvotes: 3
Reputation: 1604
Problem is inside the container the opened port is 80
and docker is exposing 32795
for external connections
Wordpress configuration is pointing to port 32795
, you might expose port 80
by doing docker run -p 80:80
and change wordpress configuration to use port 80
If you can't use port :80
a little bit more complicated solution is to use iptables
port forwarding internally
Example
➜ ~ docker run -d --cap-add=NET_ADMIN --cap-add=NET_RAW -p 5000:80 nginx
835b039cc92bd9f32b960181bf370d39869c88f5a757423966b467fe01ac219e
➜ ~ docker exec -it 835b039cc92bd9 bash
root@835b039cc92b:/# apt update -qqq ; apt install iptables -yqqq
root@835b039cc92b:/# iptables -t nat -A OUTPUT -o lo -p tcp --dport 5000 -j REDIRECT --to-
port 80
root@835b039cc92b:/# apt install telnet -yqqq
root@835b039cc92b:/# telnet localhost 5000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
^]
telnet> quit
Connection closed.
root@835b039cc92b:/# exit
# from outside the container
➜ ~ telnet localhost 5000
Trying ::1...
Connected to localhost.
Escape character is '^]'.
^]
telnet> quit
Connection closed.
Upvotes: 2