PHP api on linux machine throwing Connection Refused error on accessing - php

I have hosted website and api on apache server on linux machine. I am trying to access the api through node js (using request module)which is on the same network. From outside that network, the api is accessible and working fine. I have many apis on the machine and only few are throwing this error. Recent change which was made to server is changing the cookie domain from foo.bar.com to *.bar.com in php.ini file. The website is working good. There is not much load on the server too. Any help appreciated.

A "connection refused" error means a TCP connection can't be established, so the cookie domain change should not have an effect here.
Are you sure it's a Node.js "connection refused" error, and not, say, the API itself being able to connect somewhere else? Can you give us the exact error message, with any traceback, etc., context?
You say there are many APIs (assuming API servers) on the machine and only some fail (assuming you tested this from the machine that is having problems connecting to the API server machine).
Are the working servers on different ports compared to the non-working ones?
Do those servers work from within the network? You say they're working fine outside of it. (It's possible that your local network has a firewall policy that prohibits this local connection.)
Can you double-check that the non-working servers are actually running? (An easy way to establish this would be running ss -ltpn; it should give you a list of listening TCP ports and their associated processes.)

Related

"Connection Refused" via PHP cURL from GoDaddy Hosting to internally hosted Radarr server's API (jQuery works though?!)

I'm at a complete loss as to why this is failing, so get ready for the novel describing exactly what I'm trying to accomplish and what I've tested so far.
Goal:
I'm building a webpage on my GoDaddy hosting account that I want to connect to my locally hosted Radarr server's API via PHP cURL.
I want to use PHP so I can obfuscate the IP, port, and APIKey on the client side. Plus, some of Radarr's API calls I would like to use cannot be run via query string.
Problem:
No matter what I try, I am getting nothing but the following error:
Failed to connect to <MY PUBLIC IP ADDRESS> port <PORT NUMBER>: Connection refused
(And yes, this is the publicly opened port, not the internal port on the server.)
Setup:
I installed Radarr on a FreeNAS (11.3-U5) jail hosted in my home. This is working beautifully.
I setup the FreeNAS jail with a dedicated IP address instead of allowing it to NAT internally, just to make sure it doesn't cause any issues.
I configured port forwarding on my router to allow external traffic into the Radarr server. This is working. Note: Xfinity is my ISP, but I purchased the router separately.
I have a GoDaddy hosting account where I've written a webpage to tie into Radarr's API on my local network. Currently, the webpage is also working beautifully to query data from the API, BUT it's connecting to Radarr via $.getJSON with JavaScript and jQuery.
(Before anyone says it, yes, I know GoDaddy hosting isn't the best option, but it's the one I'm using.)
Testing:
I swear I've tested EVERYTHING and I don't know why this is failing.
This IS working through the JavaScript/jQuery solution, meaning the Radarr server is up and running, the port is properly forwarded through my router, and GoDaddy's hosting isn't blocking the connection.
I CAN access the raw JSON API response in the browser simply by entering the full API URL call.
And while I'd say I am versed in PHP, I'm certainly no expert, so I even tried pulling a generic PHP cURL script from another StackOverflow post, changing the URL to mine, and running that with no luck. Note: The original script DID work to connect to another external API though.
Then I tried Postman, which worked, and I used Postman to create a PHP script, but that script failed.
All of the functional testing done on my local network was done using my publicly facing IP address. However, just to be certain, I also tried reaching the API through the browser off my network, and that worked just fine.
In a desperate attempt, I also reached out to GoDaddy support to see if they had any ideas. They went as far as creating a test PHP cURL script in the same hosting directory and had it simply pull Google's homepage. That worked just fine.
After GoDaddy was unable to help, I setup a free hosting account and free subdomain on AwardSpace, uploaded the script, and that failed too.
In digging into the Connection Refused error, someone suggested just trying to ping the IP through PHP. I attempted this, but it returned 100% packet loss. Also, I logged into my router and watched the incoming connections as I tested. Using the jQuery solution, I saw the incoming connection and it worked great. Using the PHP solution, it didn't register anything inbound.
Lastly, I have confirmed that the publicly opened port on my router is in the list of blocked port by Xfinity. However, since I can access the server externally through the browser and via the jQuery script, that can't be the issue.
There seem to be many, many, many articles online about the general Connection Refused error, but I haven't found a solution to my problem from any of them.
Does anyone have any suggestions?

504 gateway time-out server didn't respond in time issue

I've looked throughout this site to see if I could find a solution but haven't found one.
I have a problem with a 504 gateway time-out server message that keeps popping up.
I was able to successfully setup my MySQL database to capture data from my webpage, with dbconnect.php, using my localhost/index.html. However, when I try to access it via my Virtualbox(running windows 7/10) I keep getting a 504 gateway time-out server didn't respond in time, message. I changed my $host name from localhost to supporthtech.hopto.org(I'm using NOIP). I also increased my max_input_time and max_execution_time from 120 to 3000. That doesn't seem to help. On my VM, I'm using a proxy server to mimic someone from outside my network trying to login to my website.
Like I've said at the beginning. MySQL database is able to successfully collect information when I setup my website locally(using localhost/index.html).
Any ideas would be greatly appreciated. Thanks!
I would expect you to run the web server from the same host as your database is running on, so you should continue to connect from the web page to "localhost" - regardless of how your browser is connecting to the web page, the connection between the database and the web server continues to be local. So regardless of where in the world or which virtual machine you're using, your browser should connect to the web server which you're running on the same host as the database server. There's no need to change the host string for your PHP script for the database connection if you're accessing from another host, since to the web server the database host hasn't changed. This is one of the great things about networking, if you connect to the web server it doesn't matter what is going on behind the scenes on the network because, to the web browser, all it has to do is talk to the web server; the details under the web server can be as complex or simple as your topology requires.
That seems to be the most likely cause of your trouble, so I suggest changing the connection host back to localhost and accessing your web server itself remotely. If that causes you trouble, then there's something else wrong with your web server configuration (or ISP, or port forwarding on your router, etc) that you can ask another question about.

HTTP_Request call works in browser, timeout in web app

I have a web application which gets data from itself via a REST API in JSON format. I am in the process of moving this site to a new server on a new host. I have everything moved, same database, same files. The main differences would be that PHP is running as a module on the new server instead of FastCGI and the new host has a client-configurable-firewall.
The web app makes the API call by using Pear's HTTP_Request object (GET method). When I run the web app that makes the call, it spins until it finally returns a "Connection timed out" error.
However, if I echo the URL being used by the call and then hit that directly in my browser it returns all the JSON data instantly.
I am wondering if this could be a firewall issue: port or protocol used by the guts of Pear's HTTP_Request object blocked? (There is currently a firewall policy allowing traffic on port 80 from any IP).
Or a permission issue: PHP running as a module is more sensitive to this.
Any ideas would be greatly appreciated!
As the new server is still only being tested using the IP address, the internal web application was attempting to access itself via an external IP. From the server itself, the external IP is not available. It has to be changed to point to the internal network IP for testing.
Once the domain name is moved this will become a non-issue again.

NuSOAP - PHP: Having server and client webservice in the same server and domain

I have a client web application (A) who tries to get the information of another application (B) with a webservice.
I've been testing it in my local machine and all went like a charm. However, when I uploaded them to my server (CentOS 6, SELinux disabled, Firewall configuration checked) I get the following error:
wsdl error: Getting http://applicationB/?wsdl - HTTP ERROR: Couldn't open socket connection to server http://applicationB/?wsdl, Error (110): Connection timed out
Of course, "applicationB" is a valid URL.
They are in the same server. One is in appa.domain.com and the other one in appb.domain.com.
I've tried to call directly the IP of the server in stead of writing the domain name, but no luck with that neither.
If I check manually the WSDL URL, I get a well formatted WSDL file, so it's not the problem.
I've tried to connect external webservices and they work well, so I think it's a problem with having the server and client webservices in the same machine (or domain).
With that in mind, I've also tried to listen to port 81 and calling the webservice via this port, so the listening port and the requesting port would not be the same. No luck neither.
I'm stuck with this, and I cannot get more ideas to solve it or to find a workaround.
Anyone of you maybe have experienced this problem before and know how to solve it?
Thanks in advance for your time and answers!
EDIT
I've been trying to connect to my localhost webpage via command line, using Lynx browser from my server and I can't not access the page, even trying with its IP. It cannot be reached.
Maybe this could help to find out a solution.
Finally I got it working...
I post the answer here to be helpful for future users.
The problem was in the hosts server file. As #Amenadiel told me in a comment, it wasn't resolving the names.
I changed the hosts files and it seems it took more than I expected (I made the changes 3 days before and they weren't applied yet) so I discarded the hosts issues as an option. But it seems it was the only problem.
Why, then, didn't work neither when I tried to reach it using its IP? Well, it's because of the server nature. It's a server hosted in the Cloud, so it will be - for sure - a Virtual Machine.
It has a public IP (the one I was pointing to) and a private LAN IP. The server could not see the public IP, so if I was about to use one, it should have been the private (LAN) one.
Thanks again to all of you for your answers and your patience with this server side newbie!

connecting to firewalled MS-SQL server that requires Windows Authentication via proxy?

So I need to connect to a mssql server via Windows Authentication from a Unix server. Here are the obstacles:
The db admin created a service account but made it Windows-Auth only, meaning I can't pass the username and password directly to the server to connect.
The admin also added my host's server to the firewall so that it would only accept requests from my host machine.
My host server has mssql enabled via freetds/sybase-dblib, but has the default 'secure-connections: Off' still set.
I have a similar set up on my personal machine, but with secure-connections on, but I can't connect that way since I'm firewalled.
So I'm wondering if it's possible to set up a proxy of sorts on my host so that I can start the connection on my personal machine using my local freeTDS library, but have the request pass to the host which would (in my dream world) not require secure connections to be on but simply would pass the request along so that it came from my non-firewalled host but using the correct authentication method.
If anyone is not familiar with how Windows-Authentication works, it's a type of Kerberos authentication where the client machine makes the request to the remote server so that credentials are never actually sent (and thus can't be compromised by a man-in-the-middle). So I'm very doubtful that this can be done, since at some level my host machine has to do the actual work. But i thought I'd ask since I'm not totally clear on the deeper mechanics and because I really want to get this to happen.
I guess another way of looking at it is I want to use my host as a kind of VPN.
Also, I am working with my host admins to find a more long-term solution but I need to see the database as soon as possible so I can have something working when the problem gets fixed.
Why don't you try SSH port forwarding? Ie. you connect to your host server, and tell it to forward a local port to the sql server. Then you connect on your local machine using localhost:port and your connection will be tunneled over ssh through your host server.
If your local machine is a Windows machine then just download PuTTY and follow these instructions to set up port forwarding : http://www.cs.uu.nl/technical/services/ssh/putty/puttyfw.html.
The question is of course whether your Windows credentials will be passed, but in theory this should work :p.

Categories