Running app on non-80 ports is not working
iammichiel opened this issue · comments
Hello,
When trying to run an app using fatfree on non standard port, redirections are broken.
For instance :
php -S 127.0.0.1:9000 -t www
The following variables are automatically set :
$_SERVER['SERVER_NAME'] => 127.0.0.1:9000
$_SERVER['PORT'] => "9000"
Meaning when a redirection is performed by the app : (reroute function in base.php L1532)
$port=$this->hive['PORT'];
$port=in_array($port,[80,443])?'':(':'.$port);
$url=$this->hive['SCHEME'].'://'.
$this->hive['HOST'].$port.$this->hive['BASE'].$url;
It will thus redirect to 127.0.0.1:9000:9000
.
The same is true as well for Apache or nginx running behind a load balancer on non-default ports.
When using the built-in PHP server, there shouldn't be any problem.
I just made the following test on 2 servers (PHP 5.6 and 7.4):
mkdir issue1246
cd issue1246
composer require "bcosca/fatfree-core:3.7.3"
cat << "EOM" > index.php
<?php
require('vendor/autoload.php');
$f3=Base::instance();
echo $f3->format('host={0} port={1}',$f3->HOST,$f3->PORT),PHP_EOL;
EOM
php -S 127.0.0.1:9000 -t .
Request: curl -s 'http://localhost:9000/'
Response: host=127.0.0.1 port=9000
When using a web server, SERVER_NAME
is set by the web server, not by the framework. So I suspect an issue with either the server or the load balancer configuration.
closing this, because it's invalid.