'Changing port on Apache Web Server results in "Connection refused"
I am running an Apache Web Server on my Raspberry Pi, which is basically just executing a CGI executable which is called by a PHP script, which is running on a public Hosting-provider.
To secure my Pi, I am denying all access except for the IP of the public Hosting-provider.
For this I have modified the file /etc/apache2/apache2.conf like this:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all denied
</Directory>
The IP of the Hosting-Provider gets enabled in the file: /var/www/.htaccess
Order Deny,Allow
Deny from all
Allow from xxx.xxx.166.34
Require ip 127.0.0.1
Require ip xxx.xxx.166.34
This is working great so far using the known port 80. When I call the PHP script on my Hosting-Provider, it reroutes a command to my Pi, and the CGI gets executed.
If I change the Apache Port on my Pi according to this guide: https://timleland.com/how-to-change-apache-port/ And I have also changed the port nr in: /etc/apache2/sites-available/000-default.conf
I am getting a "Connection refused" error at this line of my PHP script: $fh = fopen($command, "r");
Warning: fopen(http://...): failed to open stream: Connection refused in /home/vhosts/www.mysite.com/testcgi.php on line xx
This is the part my PHP Script:
function fDecode()
{
$prg = "http://xxx.my.dyndns:8080/cgi-bin/mytest.cgi";
$arg = "?someargs";
$command = $prg . $arg;
$fh = fopen($command, "r");
if(!$fh)
return(FALSE);
$output = '';
while (! feof($fh))
{
$output .= fread($fh, 1048576);
}
fclose($fh);
echo $output;
return(TRUE);
}
I have changed the port-rerouting on my router properly, and changed the PHP call with the new Port number, but can't get around the refused connection problem.
If I access my cgi script directly using my browser with http://xxx.my.dyndns:8080/cgi-bin/mytest.cgi it gets executed without problem.
But using it from my hostingprovider, which is a HTTPS:// connection, I get this connection refused problem, after changing the Port from anything else than 80.
Does anybody have a clue what might fix this ?
Update May 3 2022: Removing the restricted access to my Pi, has no effect. Problem seems to be the PHP function fopen(). As soon as any other port than 80 is used, this function fails. I guess it must be a provider issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
