f3-factory / fatfree-core

Fat-Free Framework core library
GNU General Public License v3.0
207 stars 88 forks source link

Running 3F locally on different port not 80 or 443 invalid redirect #337

Closed oleg-andreyev closed 2 years ago

oleg-andreyev commented 2 years ago

Running 3F locally on port 8000 Using xfra35/f3-multilang

$this->hive['HOST'] = 'localhost:8000'
$this->hive['PORT'] = '8000'

as result of \Base::reroute framework is trying to redirect me to http://localhost:8000:8000/en

ikkez commented 2 years ago

Of course, because your HOST var is wrong. the Hostname is always without the PORT.

Try:

$this->hive['HOST'] = 'localhost'
$this->hive['PORT'] = '8000'
oleg-andreyev commented 2 years ago

@ikkez HOST is filled from $_SERVER variable, SERVER_NAME, it's not manually configured.

xfra35 commented 2 years ago

Which web server are you running?

ikkez commented 2 years ago

this looks related https://serverfault.com/questions/924323/serverserver-name-returns-nginx-reverse-proxy-port-name https://serverfault.com/questions/493055/port-number-being-added-to-wordpress-admin-after-varnish-install?rq=1 so perhaps a nginx config thingy

oleg-andreyev commented 2 years ago

Well using Symfony CLI (symfony serve) command :) it's starting local server with php-fpm

xfra35 commented 2 years ago

So could it be related to https://github.com/bcosca/fatfree/issues/1246? Although I couldn't reproduce the issue...

ikkez commented 2 years ago

Looks like there're rare occasions where $_SERVER['SERVER_NAME'] includes a port number.. that would indeed be an issue, but I would say it's more likely a server config problem. The port should not be included here.

I wasn't able to reproduce either.

oleg-andreyev commented 2 years ago

So could it be related to https://github.com/bcosca/fatfree/issues/1246?

Although I couldn't reproduce the issue...

Yes and it's not a bug 🐞

From php.net: 'SERVER_NAME' The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host.

From CGI specs: The SERVER_NAME variable MUST be set to the name of the server host to which the client request is directed. It is a case-insensitive hostname or network address. It forms the host part of the Script-URI.

ikkez commented 2 years ago

So we can close this issue?

oleg-andreyev commented 2 years ago

@ikkez don't get me wrong, but I think issue should be fixed. I've provided CGI specs that says SERVER_NAME may have port number.

ikkez commented 2 years ago

4.1.14. SERVER_NAME

The SERVER_NAME variable MUST be set to the name of the server host to which the client request is directed. It is a case-insensitive hostname or network address. It forms the host part of the Script-URI.

  SERVER_NAME = server-name
  server-name = hostname | ipv4-address | ( "[" ipv6-address "]" )

A deployed server can have more than one possible value for this variable, where several HTTP virtual hosts share the same IP address. In that case, the server would use the contents of the request's Host header field to select the correct virtual host.

4.1.15. SERVER_PORT

The SERVER_PORT variable MUST be set to the TCP/IP port number on which this request is received from the client. This value is used in the port part of the Script-URI.

  SERVER_PORT = server-port
  server-port = 1*digit

Well, to me this looks like SERVER_NAME is name only, hence SERVER_PORT is mandatory to be set. What's new to me is that it can contain multiple host names 🤔

xfra35 commented 2 years ago

What's new to me is that it can contain multiple host names

I don't read it like this. It rather looks like a warning about web servers hosting multiple host names (which is very common). In any case, the variable contains only one host name at at time.

oleg-andreyev commented 2 years ago

Well, to me this looks like SERVER_NAME is name only

I read a bit differently, "network address" must have a port number. Example:

are different network addresses, while host/ip is the same.