Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 after framework upgrade #1084

Closed
v2k opened this issue Jan 4, 2018 · 18 comments
Closed

404 after framework upgrade #1084

v2k opened this issue Jan 4, 2018 · 18 comments

Comments

@v2k
Copy link

v2k commented Jan 4, 2018

Upgraded framework and can't seem to get by this 404; not sure where the extra "/" is coming from. Rolling back the upgrade works fine.

Not Found
HTTP 404 (GET //mydomain.com/)

[/var/www/mydomain.com/vendor/bcosca/fatfree/lib/base.php:1660] Base->error()
[index.php:21] Base->run()

Tried this in index.php:

require '../vendor/autoload.php';
$f3 = \Base::instance();
$f3->route('GET /',
    function() {
        echo 'Hello, world!';
    }
);
$f3->run();

Also tried adding a $f3->clear('CACHE');

@Ayesh
Copy link

Ayesh commented Jan 4, 2018

Looks like a malformed rewrite rule. The HTTP 404.. message should only show the relative path.
Are you sure you have the provided .htaccess file in place (if you are using Apache of course) and the web server is correctly rewriting requests? A rewrite rule set for a parent directory might be rewriting requests to the index.php file.

@ikkez
Copy link
Collaborator

ikkez commented Jan 13, 2018

You came from 3.6.2 or an older version @v2k ? AFAIK there were no path mechanics adjusted recently. 🤔

@v2k
Copy link
Author

v2k commented Jan 14, 2018

The working version was: 3.5.0-Release

I'm using nginx.

server {
  listen 80;
  server_name www.mydomain.com;
#  rewrite ^/(.*) http://mydomain.com/$1 permanent;
}

server {
    server_name mydomain.com;
    root /var/www/mydomain.com/public;

    location / {
        index index.php index.html index.htm;
        try_files $uri /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    }
}

@hardware
Copy link

hardware commented Mar 10, 2018

Same problem here : fossar/selfoss#1025

Solution was to explicitly set the SERVER_NAME variable in my nginx configuration. With docker, this variable must be set to localhost. For people who do not use docker, SERVER_NAME should be equal to the vhost domain name :

location ~* \.php$ {
  try_files $uri =404;
  include /etc/nginx/fastcgi_params;
  fastcgi_pass unix:/var/run/php5-fpm.sock;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_param SERVER_NAME rss.example.com; # or $host
}

@ikkez I think you should handle that automatically. If SERVER_NAME isn't defined, fallback to HTTP_HOST obtained from the HTTP request header.

@jtojnar
Copy link

jtojnar commented Mar 10, 2018

I managed to reproduce this with 3.6.3 and 3.6.2 (see the selfoss issue), it works with 3.6.1.

@xfra35
Copy link
Collaborator

xfra35 commented Mar 10, 2018

Ok then, here's the diff between 3.6.1 and 3.6.2: f3-factory/fatfree-core@3.6.1...3.6.2

Something must have changed...

Similar issues:
f3-factory/fatfree-core#245
#1060

@xfra35
Copy link
Collaborator

xfra35 commented Mar 10, 2018

Hmmm the only change related to HTTP variables is:

$_SERVER['REQUEST_URI']=$uri['path'].
    (isset($uri['query'])?'?'.$uri['query']:'').
    (isset($uri['fragment'])?'#'.$uri['fragment']:'');

That should not affect SERVER_NAME 😕

@jtojnar
Copy link

jtojnar commented Mar 10, 2018

bisecting confirms it started in f3-factory/fatfree-core@4d70bb4

Edit: $f3->get('ERROR.text') contains HTTP 404 (GET ) for any URL I tried.

Traceback points to https://github.com/bcosca/fatfree-core/blob/3.6.3/base.php#L1660:

[vendor/bcosca/fatfree-core/base.php:1660] Base->error()
[index.php:80] Base->run()

@xfra35
Copy link
Collaborator

xfra35 commented Mar 12, 2018

Thanks for the investigation @jtojnar

The reasoning behind that commit can be found in the discussion at f3-factory/fatfree-core@575cfda

Can you dump the value of $_SERVER['REQUEST_URI'] and $_SERVER['SERVER_NAME'] before instantiating the framework? So that we can understand what Nginx is sending.

@jtojnar
Copy link

jtojnar commented Mar 12, 2018

@jtojnar
Copy link

jtojnar commented Mar 12, 2018

@xfra35 Sorry, this is the right one:

array(26) {
  ["HTTP_ACCEPT"]=>
  string(3) "*/*"
  ["HTTP_USER_AGENT"]=>
  string(11) "curl/7.58.0"
  ["HTTP_HOST"]=>
  string(13) "localhost:900"
  ["REDIRECT_STATUS"]=>
  string(3) "200"
  ["SERVER_NAME"]=>
  string(0) ""
  ["SERVER_PORT"]=>
  string(4) "8888"
  ["SERVER_ADDR"]=>
  string(10) "172.17.0.2"
  ["REMOTE_PORT"]=>
  string(5) "58836"
  ["REMOTE_ADDR"]=>
  string(10) "172.17.0.1"
  ["SERVER_SOFTWARE"]=>
  string(12) "nginx/1.12.2"
  ["GATEWAY_INTERFACE"]=>
  string(7) "CGI/1.1"
  ["REQUEST_SCHEME"]=>
  string(4) "http"
  ["SERVER_PROTOCOL"]=>
  string(8) "HTTP/1.1"
  ["DOCUMENT_ROOT"]=>
  string(8) "/selfoss"
  ["DOCUMENT_URI"]=>
  string(10) "/index.php"
  ["REQUEST_URI"]=>
  string(1) "/"
  ["SCRIPT_NAME"]=>
  string(10) "/index.php"
  ["CONTENT_LENGTH"]=>
  string(0) ""
  ["CONTENT_TYPE"]=>
  string(0) ""
  ["REQUEST_METHOD"]=>
  string(3) "GET"
  ["QUERY_STRING"]=>
  string(0) ""
  ["SCRIPT_FILENAME"]=>
  string(18) "/selfoss/index.php"
  ["FCGI_ROLE"]=>
  string(9) "RESPONDER"
  ["PHP_SELF"]=>
  string(10) "/index.php"
  ["REQUEST_TIME_FLOAT"]=>
  float(1520892074.8389)
  ["REQUEST_TIME"]=>
  int(1520892074)
}

@xfra35
Copy link
Collaborator

xfra35 commented Mar 12, 2018

Ok thanks.

Can you try one last thing? echo gethostname(); at the top of your index.php.

@jtojnar
Copy link

jtojnar commented Mar 12, 2018

string(12) "3665e2ad6430"

That seems to be the container id:

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                   NAMES
3665e2ad6430        selfoss             "run.sh"            2 minutes ago       Up About a minute   0.0.0.0:900->8888/tcp   nostalgic_hermann

@jtojnar
Copy link

jtojnar commented Mar 12, 2018

Apparently, $uri is false in f3-factory/fatfree-core@4d70bb4#diff-22b1ffa797ed0997a20765c7cf8a6549R2249, resulting in empty-string $_SERVER['REQUEST_URI'].

@jtojnar
Copy link

jtojnar commented Mar 12, 2018

It is false because the constructed URI from the first commit does not contain SERVER_NAME. Maybe we could just use a dummy server name when one is not available – it is not needed anyway.

xfra35 added a commit to f3-factory/fatfree-core that referenced this issue Mar 13, 2018
@xfra35
Copy link
Collaborator

xfra35 commented Mar 13, 2018

The framework expects SERVER_NAME to be properly set on several places, not only on this line.

If this variable is not set, the framework falls back to the host name:

$_SERVER['SERVER_NAME']=gethostname();

In your case, the variable is set to an empty string, in which case the fallback doesn't apply.

Tell me if f3-factory/fatfree-core@8bf3b4c fixes the issue.

@jtojnar
Copy link

jtojnar commented Mar 13, 2018

@xfra35 can confirm it works.

@fbranco76
Copy link

fbranco76 commented Aug 16, 2022

Hi, i writed a controller function to return path on windows directories and files, but after c: read, all return this error:

URL: http://localhost/costa/api/v1/dados/dir/c:/windows

Error:
HTTP 404 (GET /v1/dados/dir/c:/windows)

[C:/desenv/lib/fatfree/3.6.3/base.php:1660] Base->error()
[C:/desenv/projs/costa/api/index.php:27] Base->run()

function code:
`public function getDir($unidade) {
$x = $this->getDefault('PARAMS.unidade','');
$chars = strlen($x);
$cdp = 0;
$cdb = 0;
for($i = 0; $i < $chars; $i++) {
if($x[$i] == ':') {
$cdp = $cdp + 1;
}
if($x[$i] == '\') {
$cdb = $cdb + 1;
}
}
if($cdp == 0) {
$x = $x.':';
}
if($cdb == 0) {
$x = $x.DIRECTORY_SEPARATOR;
}
$pasta = dir($x);
$ponteiro = 0;
while($arquivo = $pasta->read()) {

  if(!is_file($x.$arquivo)) {       
    $result[$ponteiro]['tipo']     = 'p';
    $result[$ponteiro]['id']       = $ponteiro;
    $result[$ponteiro]['completo'] = $x.$arquivo;
    $result[$ponteiro]['arquivo']  = $arquivo;
    $result[$ponteiro]['tamanho']  = '0';   
   } else {
    $tamanho = @filesize($x.$arquivo);       
    $result[$ponteiro]['tipo']     = 'a';
    $result[$ponteiro]['id']       = $ponteiro;
    $result[$ponteiro]['completo'] = $x.$arquivo; 	  
    $result[$ponteiro]['arquivo']  = $arquivo;
    $result[$ponteiro]['tamanho']  = $tamanho;
   }
   $ponteiro++;

 }
 $this->saida = $this->makeResponseForResult('',$result);
} // function getPastas`

What i have to do, to correct this???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants