Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-07

Nginx, FastCGI and /module/action vs ?module=module&action=action

10 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

leledumbo

I have a web app that works fine with embedded http server, but due to its current bugs, I need to switch to something more reliable. So I choose FastCGI and a great web server for this so far is Nginx for me. This is the configuration for my web:

server {
  listen      80;
  index       /index/home;
  server_name tkd1depok.org www.tkd1depok.org;
  location / {
    fastcgi_pass  localhost:9000;
    fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    include       fastcgi_params;
  }
}

It runs OK, but I can't use /module/action syntax, I have to use GET style (?module=module&action=action) to get the correct execution. Furthermore, it can't also use action without setting ActionVar of the module (which is not required for embedded server), proven by GetActionName in fphttp returning empty string. So if I would like to use /module/action syntax, is it possible with fpfcgi?

Reply by email

Michael Van Canneyt
to leledumbo
leledumbo wrote
I have a web app that works fine with embedded http server, but due to its current bugs, I need to switch to something more reliable.

Please report any bugs you find.
I know of only 1 bug that is connected to reliability.

Show quoted text 22 lines
So I choose FastCGI and a great web server for this so far is Nginx for me. This is the configuration for my web: server { listen 80; index /index/home; server_name tkd1depok.org www.tkd1depok.org; location / { fastcgi_pass localhost:9000; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; include fastcgi_params; } } It runs OK, but I can't use /module/action syntax, I have to use GET style (?module=module&action=action) to get the correct execution. Furthermore, it can't also use action without setting ActionVar of the module (which is not required for embedded server), proven by GetActionName in fphttp returning empty string. So if I would like to use /module/action syntax, is it possible with fpfcgi?

I use it like that under apache since a long time, on windows and Linux, both with mod_factgi and mod_fcgid.

It's probably a limitation/bug of the nginx server ? Module/action syntax depends on how the PATHINFO variable is passed to the CGI/FastCGI script.

Michael.

Reply by email

leledumbo
to Michael Van Canneyt
Please report any bugs you find.

I know of only 1 bug that is connected to reliability.

I would, but the error is intermittent and it's difficult to create a test program that always generates the bug.

Module/action syntax depends on how the PATHINFO variable is passed to the CGI/FastCGI script

OK, I'll try dumping it. Anyway, does cgidebug define could help?

Reply by email

Luiz Americo Pereira Camara
to leledumbo
leledumbo wrote
It's indeed nginx fastcgi configuration issue, I've managed to make it work somehow by reading its documentation. Thanks :)

Can you post your config here so we can also learn how to configure nginx?

Luiz

Reply by email

leledumbo
to Luiz Americo Pereira Camara

Basically I just have to add this:
http://wiki.nginx.org/HttpFastcgiModule#fastcgi_split_path_info

location / {
	fastcgi_split_path_info ^((?U).+www.tkd1depok.org)(/?.+)$;
	fastcgi_param  PATH_INFO          $fastcgi_path_info;
	fastcgi_param  PATH_TRANSLATED    $document_root$fastcgi_path_info;
        fastcgi_param  SCRIPT_FILENAME

$document_root$fastcgi_script_name;
...
# previous configuration
}

and that's the cause of empty PATH_INFO. I'm still having an issue with fpwebfile can't map uri to the correct file (it returns empty string), but I guess it shouldn't be difficult to solve.

Reply by email

Luiz Americo Pereira Camara
to leledumbo: Basically I just have to add this: http://wiki.nginx.org/HttpFastcgiModule#fastcgi_split_p…
leledumbo wrote 18 lines
Basically I just have to add this: http://wiki.nginx.org/HttpFastcgiModule#fastcgi_split_path_info location / { fastcgi_split_path_info ^((?U).+www.tkd1depok.org)(/?.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; ... # previous configuration } and that's the cause of empty PATH_INFO. I'm still having an issue with fpwebfile can't map uri to the correct file (it returns empty string), but I guess it shouldn't be difficult to solve.

Thanks

Luiz

Reply by email

leledumbo
to leledumbo: Basically I just have to add this: http://wiki.nginx.org/HttpFastcgiModule#fastcgi_split_p…

Seems like the old IncludeHTTPPathDelimiter bug strikes back (AFAIR it's been closed when I said Marco's patch works), I need to change:

procedure RegisterFileLocation(const ALocation,ADirectory: String);
begin
  ...
  if (ADirectory='') then
Locations.Values[IncludeTrailingPathDelimiter(ALocation)]:=ExtractFilePath(ParamStr(0))
  else
Locations.Values[IncludeTrailingPathDelimiter(ALocation)]:=IncludeTrailingPathDelimiter(ADirectory);
  ...
end;

to

procedure RegisterFileLocation(const ALocation,ADirectory: String);
begin
  ...
  if (ADirectory='') then
Locations.Values[IncludeHTTPPathDelimiter(ALocation)]:=ExtractFilePath(ParamStr(0))
  else
Locations.Values[IncludeHTTPPathDelimiter(ALocation)]:=IncludeTrailingPathDelimiter(ADirectory);
  ...
end;

Furthermore, nginx supports multiple servers (so that we could have: http://localhost/what/ever/it/is/www.realsite.com) which would cause problem with MapFileName code because BaseURL property takes the first slash after http:// up to the last slash (in case of:
http://localhost/what/ever/it/is/www.realsite.com/css/mycss.css, BaseURL = /what/ever/it/is/www.realsite.com/css/). I'll report this.

Reply by email