Recent

Author Topic: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux  (Read 107839 times)

matthius

  • Full Member
  • ***
  • Posts: 135
  • Creating VRAD...
    • LIBERLOG - Développement rapide
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #30 on: December 12, 2020, 03:08:47 pm »
FastCgiExternalServer command is not recognized.

I use 2015 port in my Fast CGI. I use Listen command.
M. GIROUX
13 rue Tanguy PRIGENT
35000 RENNES - France
(33)(0)2 23 46 06 54
http://liberlog.fr

mobilevil

  • Jr. Member
  • **
  • Posts: 68
    • http://www.kachun.com
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #31 on: December 12, 2020, 03:37:32 pm »
are you using apache? which OS?
focus on port HTTP port 80 first.

the listen directive define the port apache use to talk to browser. not FCGI. usually the listen directive is already defined in the default config. both 80 for HTTP and 443 for HTTPS.

the FastCgiExternalServer directive is inside <IfModule mod_fastcgi.c> block, which is only valid if
LoadModule fastcgi_module "modules/mod_fastcgi.so" is also defined.
FastCgiExternalServer tell apache to use the specified port number to talk to the FCGI program.

browser -> port 80 -> apache -> port 2015 -> FCGI

so apache "listen" to port 80, and FCGI "listen" to port 2015.



matthius

  • Full Member
  • ***
  • Posts: 135
  • Creating VRAD...
    • LIBERLOG - Développement rapide
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #32 on: December 12, 2020, 04:59:00 pm »
I use this config :
LoadModule fastcgi_module "/usr/lib/apache2/modules/mod_fastcgi.so"

<Directory /var/www/cgi-bin>
Options All
AllowOverride All
Require all granted
Options +ExecCGI +FollowSymLinks

   SetHandler fcgid-script
   AddHandler fcgid-script .cgi
    Order allow,deny
    Allow from all
</Directory>

FastCgiExternalServer "/var/www/cgi-bin/cgi2015.cgi" -host 127.0.0.1:2015 -idle-timeout 30 -flush

ScriptAlias /cgi-bin "/var/www/cgi-bin"

I got that it is unable to connect. After it has no header. But i have created a response.
M. GIROUX
13 rue Tanguy PRIGENT
35000 RENNES - France
(33)(0)2 23 46 06 54
http://liberlog.fr

matthius

  • Full Member
  • ***
  • Posts: 135
  • Creating VRAD...
    • LIBERLOG - Développement rapide
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #33 on: December 12, 2020, 05:01:58 pm »
Here is the main unit :

program fcgihellow;

{$mode objfpc}{$H+}

uses
  fpFCGI, u_hellofcgi;

begin
  Application.Title:='fcgihellow';
  { Uncomment the port setting here if you want to run the
    FastCGI application stand-alone (e.g. for NGINX) }
  Application.Port:=2015; // For example
  Application.Initialize;
  Application.Run;
end.
               

Here is the web module :

unit u_hellofcgi;

{$mode objfpc}{$H+}

interface

uses
  SysUtils, Classes, httpdefs, fpHTTP, fpWeb;

type

  { TFPWebModule1 }

  TFPWebModule1 = class(TFPWebModule)
    procedure DataModuleRequest(Sender: TObject; ARequest: TRequest;
      AResponse: TResponse; var Handled: Boolean);
  private

  public

  end;

var
  FPWebModule1: TFPWebModule1;

implementation

{$R *.lfm}

{ TFPWebModule1 }

procedure TFPWebModule1.DataModuleRequest(Sender: TObject; ARequest: TRequest;
  AResponse: TResponse; var Handled: Boolean);
var
  LName: String;
begin
  LName := ARequest.QueryFields.Values['Name'];
  if LName = EmptyStr then
    with AResponse.Contents do
    begin
      Add('<form action="' + ARequest.URI + '" method="GET"');
      Add('<label for="name">Please tell me your name:</label>');
      Add('<input type="text" name="name" id="name" />');
      Add('<input type="submit" value="Send" />');
      Add('</form>');
    end
  else
    AResponse.Content := 'Hello World, ' + LName + '!';
  Handled := true;
end;

initialization
  RegisterHTTPModule('TFPWebModule1', TFPWebModule1);
end.     
M. GIROUX
13 rue Tanguy PRIGENT
35000 RENNES - France
(33)(0)2 23 46 06 54
http://liberlog.fr

matthius

  • Full Member
  • ***
  • Posts: 135
  • Creating VRAD...
    • LIBERLOG - Développement rapide
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #34 on: December 13, 2020, 03:19:16 pm »
iptables and ufw accept entering sockets.
M. GIROUX
13 rue Tanguy PRIGENT
35000 RENNES - France
(33)(0)2 23 46 06 54
http://liberlog.fr

matthius

  • Full Member
  • ***
  • Posts: 135
  • Creating VRAD...
    • LIBERLOG - Développement rapide
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #35 on: December 13, 2020, 06:24:11 pm »
I reinstalled apache2. There is always the error.
M. GIROUX
13 rue Tanguy PRIGENT
35000 RENNES - France
(33)(0)2 23 46 06 54
http://liberlog.fr

zamronypj

  • Full Member
  • ***
  • Posts: 130
    • Fano Framework, Free Pascal web application framework
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #36 on: December 13, 2020, 11:46:13 pm »
you should inspect error from apache error log to find what is wrong.

if you use Apache mod_proxy_fcgi, you can setup virtual host using ProxyPassMatch as follows
Code: XML  [Select][+][-]
  1. <VirtualHost *:80>
  2.      ServerName www.example.com
  3.      DocumentRoot /path/to/app/public
  4.  
  5.      <Directory "/path/to/app/public">
  6.          Options +ExecCGI
  7.          AllowOverride FileInfo
  8.          Require all granted
  9.      </Directory>
  10.  
  11.     ProxyRequests Off
  12.     ProxyPassMatch /(css|images|js).* !
  13.     ProxyPassMatch ^/(.*)$ fcgi://127.0.0.1:2015
  14. </VirtualHost>
  15.  

mod_proxy_fcgi is built-in module since Apache 2.4, you just need to enable it. For example on Debian Linux

Code: Bash  [Select][+][-]
  1. $ sudo a2enmod proxy_fcgi
  2.  

Code: XML  [Select][+][-]
  1.     ProxyRequests Off
  2.     ProxyPassMatch /(css|images|js).* !
  3.     ProxyPassMatch ^/(.*)$ fcgi://127.0.0.1:2015
  4.  

First line turn off forward proxy. Second line tells Apache to serve any files from css, images or js directory in document root directly. Third line tells Apache to pass everything else to application listen on 127.0.0.1 port 2015. "fcgi:" tells mod_proxy to use mod_proxy_fcgi.
« Last Edit: December 14, 2020, 12:14:06 am by zamronypj »
Fano Framework, Free Pascal web application framework https://fanoframework.github.io
Apache module executes Pascal program like scripting language https://zamronypj.github.io/mod_pascal/
Github https://github.com/zamronypj

matthius

  • Full Member
  • ***
  • Posts: 135
  • Creating VRAD...
    • LIBERLOG - Développement rapide
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #37 on: December 14, 2020, 07:42:14 pm »
Thanks for reply !

I got always the same error :
[Mon Dec 14 19:40:33.894880 2020] [proxy:error] [pid 10109:tid 140072876771072] (111)Connection refused: AH00957: FCGI: attempt to connect to 127.0.0.1:2015 (127.0.0.1) failed
[Mon Dec 14 19:40:33.894975 2020] [proxy_fcgi:error] [pid 10109:tid 140072876771072] [client 127.0.0.1:52044] AH01079: failed to make connection to backend: 127.0.0.1

I use Lazarus 2.0.10
« Last Edit: December 14, 2020, 07:44:00 pm by matthius »
M. GIROUX
13 rue Tanguy PRIGENT
35000 RENNES - France
(33)(0)2 23 46 06 54
http://liberlog.fr

zamronypj

  • Full Member
  • ***
  • Posts: 130
    • Fano Framework, Free Pascal web application framework
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #38 on: December 15, 2020, 12:34:46 am »
You need to check if

  • Apache and application is on same server
  • application does run and listen on specified port

To check if application listen on correct port

Code: Bash  [Select][+][-]
  1. $ netstat -tunlp | grep 127.0.0.1:2015
Fano Framework, Free Pascal web application framework https://fanoframework.github.io
Apache module executes Pascal program like scripting language https://zamronypj.github.io/mod_pascal/
Github https://github.com/zamronypj

matthius

  • Full Member
  • ***
  • Posts: 135
  • Creating VRAD...
    • LIBERLOG - Développement rapide
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #39 on: December 15, 2020, 01:05:27 pm »
No result.

Must i keep FastCgiExternalServer ?
M. GIROUX
13 rue Tanguy PRIGENT
35000 RENNES - France
(33)(0)2 23 46 06 54
http://liberlog.fr

cappe

  • Full Member
  • ***
  • Posts: 156
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #40 on: December 15, 2020, 04:25:28 pm »
but if you write like this something comes back

    $ netstat -tunlp | grep 2015

matthius

  • Full Member
  • ***
  • Posts: 135
  • Creating VRAD...
    • LIBERLOG - Développement rapide
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #41 on: December 15, 2020, 05:16:34 pm »
No result too.
M. GIROUX
13 rue Tanguy PRIGENT
35000 RENNES - France
(33)(0)2 23 46 06 54
http://liberlog.fr

zamronypj

  • Full Member
  • ***
  • Posts: 130
    • Fano Framework, Free Pascal web application framework
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #42 on: December 16, 2020, 02:34:52 am »
If netstat command above shows no result, it means your application is not running. That is why Apache cannot connect to your application. You need to run application first.
Fano Framework, Free Pascal web application framework https://fanoframework.github.io
Apache module executes Pascal program like scripting language https://zamronypj.github.io/mod_pascal/
Github https://github.com/zamronypj

egsuh

  • Hero Member
  • *****
  • Posts: 834
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #43 on: December 16, 2020, 03:52:11 am »
I have no experience with Apache, and I can run FCGI modules on IIS - Windows 10 successfully.

Logically thinking, IIS runs FCGI program so I do not assign separate port -- I think the same applies to Apache. Separate port is necessary to run it as HTTP server, which responses directly, not via IIS or Apache. 

First, test with following main program.

Code: Pascal  [Select][+][-]
  1. begin
  2.    Application.Title:='fcgihellow';
  3.   { Uncomment the port setting here if you want to run the
  4.     FastCGI application stand-alone (e.g. for NGINX) }
  5.   // Application.Port:=2015; // For example
  6.  
  7.    LegacyRouting:= True;
  8.    Application.Initialize;
  9.    Application.Run;
  10. end.
  11.  

In IIS, I have to set Handler Mappings --- I have to add mapping for the application program. Don't know how to do this in Apache.

Important thing is that allowPathInfo should be set TRUE. Again, no idea whether this is applicable to Apache.

But as I posted in other posts, Free Pascal fCGI model is not perfect --- I believe it has some problem in memory management. (the author acknowledges this). 

Anyway please let me know your result. I'd like to have as many developers of Lazarus webserver as possible.^^

matthius

  • Full Member
  • ***
  • Posts: 135
  • Creating VRAD...
    • LIBERLOG - Développement rapide
Re: FCGI (FastCGI) step by step, using fpweb/fcl-web for Windows/Linux
« Reply #44 on: December 16, 2020, 12:57:19 pm »
I have deleted link to fastcgi module.

It does always no result.
M. GIROUX
13 rue Tanguy PRIGENT
35000 RENNES - France
(33)(0)2 23 46 06 54
http://liberlog.fr

 

TinyPortal © 2005-2018