Code Monkey home page Code Monkey logo

fcgiwrap's Introduction

fcgiwrap

Info:Simple FastCGI wrapper for CGI scripts
Homepage:http://nginx.localdomain.pl/wiki/FcgiWrap
Author: Grzegorz Nosek <[email protected]>
Contributors:W-Mark Kubacki <[email protected]> Jordi Mallach <[email protected]>

This page has been translated into Spanish language by Maria Ramos from Webhostinghub.com/support/edu.

License

This software is released under the MIT license. See COPYING for details.

Features

  • very lightweight (84KB of private memory per instance)
  • fixes broken CR/LF in headers
  • handles environment in a sane way (CGI scripts get HTTP-related env. vars from FastCGI parameters and inherit all the others from fcgiwrap's environment)
  • no configuration, so you can run several sites off the same fcgiwrap pool
  • passes CGI stderr output to fcgiwrap's stderr or FastCGI stderr stream

Installation

requirements

Makefile and configure script is generated by GNU autotools. Therefore you need the latter.

pkg-config is needed, else you may get AC_DEFINE errors.

fcgiwrap links to dev-libs/fcgi which can be obtained from http://www.fastcgi.com/ .

fcgiwrap also uses (but not requires) systemd for socket activation.

procedure

To install:

autoreconf -i
./configure
make
make install

fcgiwrap will be copied to /usr/local/sbin/fcgiwrap if you did not set --prefix for configure or DESTDIR for the makefile.

usage

Most probably you will want fcgiwrap be launched by www-servers/spawn-fcgi. Or you could use the author's Perl launcher - see the homepage for that.

There are two modes of fcgiwrap operation:
  • when SCRIPT_FILENAME is set, its value is treated as the script name and executed directly.
  • otherwise, DOCUMENT_ROOT and SCRIPT_NAME are concatenated and split back again into the script name and PATH_INFO. For example, given a DOCUMENT_ROOT of /www/cgi and SCRIPT_NAME of /subdir/example.cgi/foobar, fcgiwrap will execute /www/cgi/subdir/example.cgi with PATH_INFO of /foobar (assuming example.cgi exists and is executable).

fcgiwrap's People

Contributors

acieroid avatar falconindy avatar gnosek avatar goochjj avatar jmallach avatar justinclift avatar lekensteyn avatar mark-kubacki avatar ronhuang avatar stromnet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fcgiwrap's Issues

fcgiwrap doesn't start as service on FreeBSD 13

Hi!
When I install fcgiwrap on FreeBSD 13.0 + nginx, I can't start service with:

root@myhost:/var/run/fcgiwrap# service fcgiwrap start
Starting fcgiwrap.
root@myhost:/var/run/fcgiwrap# service fcgiwrap status
fcgiwrap is not running.
root@myhost:/var/run/fcgiwrap#

There are no errors, but also no pid file and sock.
when I manually execute this script (writting for debug):

root@myhost:~/bin# start_fcgi.sh
#!/bin/sh
/usr/sbin/daemon -S -p /var/run/fcgiwrap/fcgiwrap.pid /usr/local/sbin/fcgiwrap -c 2 -s unix:/var/run/fcgiwrap/fcgiwrap.sock
chown www:www /var/run/fcgiwrap/fcgiwrap.sock

Everything fine - I see:

root@myhost:/var/run/fcgiwrap# ls -l
total 5
-rw------- 1 root wheel 4 Apr 27 15:06 fcgiwrap.pid
srwxr-xr-x 1 www www 0 Apr 27 15:06 fcgiwrap.sock

Something wrong is in /usr/local/etc/rc.d/fcgiwrap
( I attach it, as is).
fcgiwrap.zip
For avoid any mistake, I twice install fcgiwrap - with pkg and with building from ports, but nothing change
This issue I have only on FreeBSD 13.0. I have another installation fcgiwrap on Archliux - it works fine "Just form box :-)"

With Best Wishes!!!

fcgiwrap.c:581:4: error: this statement may fall through [-Werror=implicit-fallthrough=]

Centos 8

During the step "make" I run into this error:

cc -std=gnu99 -Wall -Wextra -Werror -pedantic -O2 -g3    fcgiwrap.c  -lfcgi  -o fcgiwrap
fcgiwrap.c: In function ‘handle_fcgi_request’:
fcgiwrap.c:581:4: error: this statement may fall through [-Werror=implicit-fallthrough=]
    cgi_error("502 Bad Gateway", "Cannot execute script", filename);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fcgiwrap.c:583:3: note: here
   default: /* parent */
   ^~~~~~~

Any ideas? I tried removing -Wall, -Wextra, -Werror but the install didn't work and I can't help but feel this is why.

FCGI Wrap on OS X

Can FCGI Wrap work with NGinx on OS X?
I've installed FCGI Wrap from Homebrew, but there is no plist file to use for service start.

How properly create socket and start service without init.d script?

Support for unbuffered output

libfcgi has an internal 8k buffer which causes issues with long running scripts which output progress or similar. I made a quick patch for my needs at notr1ch@84c8b63 but it would be nice to see it officially supported.

fcgiwrap doesn't like the default fastcgi_params

Hi there,

This is how I configure the /cgi-bin/ location in the nginx configure file, it doesn't work if I include /etc/nginx/fastcgi_params, and it worked if I comment this line out. I'm assuming either fcgiwrap doesn't like some of the default fastcgi_params or the params I gave in the location block gets overwritten by the default params. could you advise?
`
location ~ ^/cgi-bin/nagios3/(..cgi.) {
include /etc/nginx/fastcgi_params;

fastcgi_pass  unix:/var/run/fcgiwrap.socket;
    auth_basic                         "Restricted";
    auth_basic_user_file               /etc/nagios3/htpasswd.users;
    fastcgi_param AUTH_USER            $remote_user;
    fastcgi_param REMOTE_USER          $remote_user;
    fastcgi_param REQUEST_METHOD       $request_method;
    fastcgi_param DOCUMENT_ROOT        /usr/lib/cgi-bin/nagios3;
    fastcgi_param SCRIPT_FILENAME      /usr/lib/cgi-bin/nagios3/$1;
    fastcgi_param SCRIPT_NAME          $1;
    fastcgi_param QUERY_STRING         $query_string;

}
`

Ability to restrict to an executing file?

From Security:

fcgiwrap doesn't verify the SCRIPT_FILENAME passed to it and will happily traverse directories upwards. I consider this the responsibility of the web server (Nginx does this just fine) but feel free to bug me if you disagree.

I want to connect cgit with nginx and so far, fcgiwrap seems the easiest option. I have considered integrating fastcgi into cgit, but that seems to much work for small benefit.

As I only want to connect nginx to cgit, would it be possible to specify a single allowed binary? This will be a defense-in-depth idea, in case the nginx user got compromised somehow, the remaining processes is not lost.

I will try to patch fcgiwrap by adding a command-line option. For now the plan is to add a single option that overrides previous ones, but in the future it could be extended to add to a list of programs or even use globbing/leading path.

Child FCGI process keeps respawning after each request

I've a nginx server which is passing requests via /var/run/fcgiwrap.socket

location /bin {
    root /var/www/;
    fastcgi_pass unix:/var/run/fcgiwrap.socket;
    include fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
 }
My C program is calling FCGI_accept() in a while loop.
 while (FCGI_Accept() >= 0) {
    blah
   }

When I hit the nginx server with my request it works once then FCGI-Accept ruturns -1 and that means the process is respawning every time I make a request.

Is there a way to have tohave fcgiwrap honour the Accept for the next call?

problem compilling

Ubuntu Lucid
autoconf (GNU Autoconf) 2.65

git clone https://github.com/gnosek/fcgiwrap.git

cd fcgiwrap

autoconf

configure.ac:32: error: possibly undefined macro: AC_DEFINE
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
configure.ac:39: error: possibly undefined macro: AM_CONDITIONAL

After main process is killed the childs still running.

OS: CentOS release 6.5 (Final) 2.6.32-431.3.1.el6.i686

fcgiwrap -c 5
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
---------------------------------------------------------------------
 5659 user      20   0  2024  384  324 S  0.0  0.0   0:00.00 fcgiwrap
 5660 user      20   0  2160  356  284 S  0.0  0.0   0:00.00 fcgiwrap
 5661 user      20   0  2160  356  284 S  0.0  0.0   0:00.00 fcgiwrap
 5662 user      20   0  2160  356  284 S  0.0  0.0   0:00.00 fcgiwrap
 5663 user      20   0  2160  356  284 S  0.0  0.0   0:00.00 fcgiwrap
 5664 user      20   0  2160  356  284 S  0.0  0.0   0:00.00 fcgiwrap

kill 5659
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
---------------------------------------------------------------------
 5660 user      20   0  2160  356  284 S  0.0  0.0   0:00.00 fcgiwrap
 5661 user      20   0  2160  356  284 S  0.0  0.0   0:00.00 fcgiwrap
 5662 user      20   0  2160  356  284 S  0.0  0.0   0:00.00 fcgiwrap
 5663 user      20   0  2160  356  284 S  0.0  0.0   0:00.00 fcgiwrap
 5664 user      20   0  2160  356  284 S  0.0  0.0   0:00.00 fcgiwrap

During installation it needs FastCGI lib. I can't install it on ternux.

➜ fcgiwrap git:(master) autoreconf -i
➜ fcgiwrap git:(master) ✗ ls
COPYING Makefile.in README.rst aclocal.m4 autom4te.cache config.guess config.h.in config.sub configure configure.ac fcgiwrap.8 fcgiwrap.c systemd
➜ fcgiwrap git:(master) ✗ ./configure
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking for pkg-config... /data/data/com.termux/files/usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for FCGX_Init in -lfcgi... no
configure: error: FastCGI library is missing

fcgiwrap.c:555:4: error: this statement may fall through

# make fcgiwrap

cc -std=gnu99 -Wall -Wextra -Werror -pedantic -O2 -g3    fcgiwrap.c  -lfcgi  -o fcgiwrap
fcgiwrap.c: In function ‘handle_fcgi_request’:
fcgiwrap.c:555:4: error: this statement may fall through [-Werror=implicit-fallthrough=]
555 |    cgi_error("502 Bad Gateway", "Cannot execute script", filename);
    |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fcgiwrap.c:557:3: note: here
557 |   default: /* parent */
    |   ^~~~~~~
cc1: all warnings being treated as errors
make: *** [<builtin>: fcgiwrap] Error 1

100 CPU usage after kill child process

OS: CentOS release 6.5 (Final) 2.6.32-431.3.1.el6.i686

fcgiwrap -c 5
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
---------------------------------------------------------------------
 5614 user      20   0  2024  384  324 S  0.0  0.0   0:00.00 fcgiwrap
 5615 user      20   0  2160  356  284 S  0.0  0.0   0:00.00 fcgiwrap
 5616 user      20   0  2160  356  284 S  0.0  0.0   0:00.00 fcgiwrap
 5617 user      20   0  2160  356  284 S  0.0  0.0   0:00.00 fcgiwrap
 5618 user      20   0  2160  356  284 S  0.0  0.0   0:00.00 fcgiwrap
 5619 user      20   0  2160  356  284 S  0.0  0.0   0:00.00 fcgiwrap

After kill any child (5615-5619)

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
---------------------------------------------------------------------
 5614 user      20   0  2024  384  324 R 99.9  0.0   0:06.42 fcgiwrap  !!!!!
 5615 user      20   0  2160  356  284 S  0.0  0.0   0:00.00 fcgiwrap
 5616 user      20   0  2160  356  284 S  0.0  0.0   0:00.00 fcgiwrap
 5617 user      20   0  2160  356  284 S  0.0  0.0   0:00.00 fcgiwrap
 5619 user      20   0  2160  356  284 S  0.0  0.0   0:00.00 fcgiwrap

Better document the license under which this code is released

I see in the comment header in the file fcgiwrap.c that this is under the MIT license, but it would be easier to find this information if you mentioned the license on the project's homepage and in the README, and if you had the license text in a file named LICENSE or COPYING.

install will fail when running as non-root user

$ make && make install
...
install -m 644 systemd/fcgiwrap.socket /usr/lib/systemd/system
install: cannot create regular file ‘/usr/lib/systemd/system/fcgiwrap.socket’: Permission denied
Makefile:9: recipe for target 'install' failed
make: *** [install] Error 1

Buffers overflow in nginx

Hello everyone. Who can tell you. If "fastcgi_buffers" is overflow, how do I find out about it? Because due to the insufficient speed of the clients, the data begins to be overwritten in "fastcgi_buffers".

Child process not detached

I'm trying to do the following: when a request is received, an immediate response 202 should be given, while a long background process is started.
In nginx.conf:

    location /do-something {
        fastcgi_pass  unix:/var/run/fcgiwrap.socket;
        # Fastcgi parameters, include the standard ones
        include /etc/nginx/fastcgi_params;
        # Adjust non standard parameters (SCRIPT_FILENAME)
        fastcgi_param SCRIPT_FILENAME /usr/local/bin/do-something.sh;
    }

/usr/local/bin/do-something.sh

#!/bin/bash
echo "Status: 202"
echo -e "Content-type: text/plain\n"

echo "Calling child process..."
/usr/local/bin/do-process.sh &
echo "Returned from child process."

exit 0

/usr/local/bin/do-process.sh

#!/bin/bash

echo "Starting child process..."
sleep 10
echo "Child process done."

exit 0

The expected result is that ampersand used in calling do-process.sh should detach the child process, and 202 code should be returned immediately, as when calling /usr/local/bin/do-something.sh from console. But when I make a request via nginx:

curl -i http://127.0.0.1/do-something

the response is not given immediately, but after 10 seconds.

I'm using spawn with config /etc/sysconfig/spawn-fcgi:

FCGI_SOCKET=/var/run/fcgiwrap.socket
FCGI_PROGRAM=/usr/local/sbin/fcgiwrap
FCGI_USER=nginx
FCGI_GROUP=nginx
FCGI_EXTRA_OPTIONS="-M 0770"
OPTIONS="-u $FCGI_USER -g $FCGI_GROUP -s $FCGI_SOCKET -S $FCGI_EXTRA_OPTIONS -F 1 -P /var/run/spawn-fcgi.pid -- $FCGI_PROGRAM"

in a CentOS 7 computer.

Is this the right way of calling a process and start a child process without waiting it to finish?

expected PATH_INFO is not set

Given the request to http://127.0.0.1/cgit/xyz/ and the relevant resulting request headers as follows::
DOCUMENT_ROOT=/var/www/localhost/htdocs/cgit/
SCRIPT_FILENAME=/var/www/localhost/htdocs/cgit/tst
REQUEST_URI=/cgit/xyz/
SCRIPT_NAME=tst
... no PATH_INFO is set.

Expected is PATH_INFO /xyz/ or similar.

You can easily test that by this CGI script::
#!/bin/sh
echo Content-type: text/plain
echo Expires: 0
echo ""
/bin/env
/bin/date

configure: error: cannot find install-sh, install.sh, or shtool in "." "./.." "./../.."

Hello,

I am facing error in centos 6 but on centos 7 its running very fine. All requirements are already fullfilled.

[root@server1 fcgiwrap]# ./configure

checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... unsupported
checking for gcc option to enable C99 features... -std=gnu99
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for FCGX_Init in -lfcgi... yes
checking for systemd... no
Package systemd was not found in the pkg-config search path.
Perhaps you should add the directory containing `systemd.pc'
to the PKG_CONFIG_PATH environment variable
No package 'systemd' found
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for vfork.h... no
checking for fcntl.h... yes
checking for limits.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for unistd.h... (cached) yes
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes
checking for pid_t... yes
checking for size_t... yes
checking for ssize_t... yes
checking for fork... yes
checking for vfork... yes
checking for working fork... yes
checking for working vfork... (cached) yes
configure: error: cannot find install-sh, install.sh, or shtool in "." "./.." "./../.."

Can't Resolve

The help would imply that you can type an fqdn such as tcp:dot.ted.qu.ad:port.

Looking at the code though, it would appear though that you can only use a dotted IP. Either the documentation or (preferably) the code should be fixed.

Provide real distfiles

Please provide real distfiles, autogenerated one (ie from tags) doesn't work well the the freebsd's ports for downloading (as the default fetch tools is configured to not follow the 302 redirect when used for ports)

it will be great to have this for packagers, thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.