php curl connection refused
Curl connection refused between applications on Docker container
I have a website (ZF1) and an API (Laravel) running on the same Docker (Laradock) container. I can access each separately through a browser, but when I make a cURL request from the website to the application, I get a null response and the header returns 0. If I output the cURL errors, then I get this:
However, if I make a cURL request to https://www.google.com from the application, then it returns a result. I also tried using file_get_contents(), but I received no response and the following warning:
I also SSHed into the Apache2 container and was able to make a successful cURL call to the API_ENDPOINT and get the expected data back. I then tried using wget to get the header info and received the following:
In case it is an Apache2 issue, here is my API VirtualHost:
And Website VirtualHost:
This is the Docker info (Windows 10/Hyper V/Docker Version 17.03.1-ce-win12 (12058) Channel: stable)
And these are the containers that I am currently running:
I am not sure what is causing the connection to be refused between the two sites on the same container. I checked my php.ini and both curl and allow_url_fopen = on were enabled. I am able access the API_ENDPOINT directly through both browser and CLI cURL and get the expected results. My best guesses at this point are some sort of port conflict, an authorization header being blocked, Apache2 configuration, or some sort of odd Docker/Laradock issue. I also thought it might of been a conflict between Apache2 and PHP-FPM, but the solutions detailed here didn’t seem to work for me.
Thank you in advanced for any assistance that you can provide.
cURL between Docker service php-fpm containers results in «Connection refused»
after looking for an answer 2 weeks along, going deep into the docker compose and docker networks documentations, I’d like to ask for some help right here.
I am creating two Web API services, let’s called them a back API ( back.api.dev ) and a front API ( front.api.dev ).
What I tried so far :
The back API is connected to a MySQL database, and the front API only sends cURL requests to the back API. Both APIs are built upon Symfony and are processed by a docker PHP-FPM container. Everything is served by a docker Apache 2.4 container.
Sending requests through Postman and cURL requests to back.api.dev & front.api.dev are both working great. It works both from my host, but also from the Apache container. I also added 127.0.0.1 back.api.dev and 127.0.0.1 front.api.dev to my /etc/hosts host machine file. The back API is well connected to the database as well.
But when I send a request to a specific front API route which runs a cURL request to the back API using GuzzleHTTP client and send the answer back to the user, I get a cURL error 7: Failed to connect to back.api.dev port 80: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://back.api.dev/api/videos/
I also tried to send cURL requests from the CLI inside the front_api container but the result is the same. I also tried to send it directly to the port 9000 handled by php-fpm but I get a cURL error 56: Recv failure: Connection reset by peer error.
Here’s the docker-compose.yml file :
Here is my back API Apache Virtualhost :
Curl «Connection Refused» when connecting to server with external IP address
I’ve created a RESTful server and I can successfully make requests and get responses when I use my local IP address. I would like it to be exposed externally to the internet. I set up a port forwarding rule but I cannot seem to get things working. From what I’m reading the «Connection Refused» with (7) means something is blocking it whether it’s a firewall or ISP issue. Any ideas on what to do?
Here’s my curl command that works with my local IP:
This is what I see when I try using my external IP address given to me by What’s my ip
Here’s the port forwarding rule I made in my router/modem
Here are my router/modem advanced settings options. I tried tweaking my firewall settings, but no luck. I tried with NAT only and also with Low Security Level with all ports checked.
Here is the port forwarding screen, should I just set 30000 as the begin and end?
Here is some python code for my server:
Tried only having 1 port, not a begin/end range and it’s expecting a range.
cURL connection refused – possible fixes
cURL is the de facto standard library for making HTTP requests from the command line. It is available on most Linux distributions or macOS, and now just make its way into Windows.
In this article, you’ll learn about cURL «Connection Refused» error and discover a few possible fixes when you encounter this error.
What does cURL connection refused really mean?
«Connection Refused» is a generic error message, it means that the connection to the server has not been successfully made. The full error message looks similar to this.
Normally, the server is to blame, but there are situations where your system configuration may have caused «Connection Refused».
If you’re a developer, chances are you misconfigured your application, have it listened on the wrong port, or something else.
Users who are working with virtualization software like Docker or Vagrant sometimes also encounter the error. The solutions will be presented in the next section of the article.
Double-check the address with a browser
Most of the time, you have to double-check the address which you’re trying to make a connection really is the correct one. Fire up a browser, try to access the original address and see whether it can connects or not.
We recommend Firefox because it uses its own proxy network stack instead of reusing system configuration, therefore you can check using your direct connection to really see through the situation without messing with proxies and stuff.
In the screenshot above, we may have to check if we started our local server at port 3000 first because the error really comes from the server.
Check your proxy configuration
Sometimes, maybe you are having a proxy server defined in your environment that blocks the connection.
If you just want to make sure you’re using a direct connection, run the following commands to unset these system variable all at once.
Inspect hosts file for misconfiguration
Web developers usually use this to direct local connections to localhost for easier testing. Sometimes, they leave the entries inside the hosts file, causing strange redirects.
It’s also possible that software on your system modify the hosts themselves, but this is not usually the case.
The solution : Empty hosts file to see whether the problem goes away.
Force IPv4
Docker/Vagrant users : add a proxy to reach the host
Users who work with virtualization software often need to connect to the host machine or another virtual machine from within the VM.
By default, the host isn’t available inside the Docker container. You must use the host machine IP address instead of localhost or 127.0.01. More details and configuration can be found at this stackoverflow page.
Using Flask/Django? Change the listening address
For users who is running their Dlask or Django app, please double check whether you use the correct address.
Почему nginx отвечает connection refused на все попытки подключения?
Файл конфигурации /etc/nginx/sites-available/default:
Буду признателен за помощь)
fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
lucifer_jr, с тем же, с которым он создан в /etc/nginx/sites-available. но лучше вообще сделайте:
это для всех конфигов из sites-available сделает симлинки в sites-enabled и перезапустит сервис nginx.
lucifer_jr, так блин вроде в любой мане пишут что надо символьные ссылки создавать для конфигов в site-enabled, чтоб они применились. ну е мае! так вот сразу и не догадаешься)
/etc/nginx/sites-available: директория, в которой хранятся «серверные блоки» для каждого сайта (серверные блоки являются приблизительным аналогом виртуальных хостов в Apache). Nginx не будет использовать конфигурационные файлы в этой директории, если они не имеют соответствующих ссылок в директории sites-enabled. Обычно все настройки серверного блока осуществляются в этой директории, а затем сайт активируется путём создания ссылки в другой директории.
/etc/nginx/sites-enabled/: в этой директории хранятся серверные блоки для активированных сайтов. Обычно это достигается путём создания ссылок на конфигурационные профили сайтов, расположенные в директории sites-available.