Code Monkey home page Code Monkey logo

cgi's Introduction

Bash CGI Example

Development server

Quickly get up an running using Python's CGIHTTPServer:

python -m CGIHTTPServer

Caveats:

  • scripts need to be placed in a sub-folder named cgi-bin/ or htbin/
  • every response gets the status 200 Script output follows

Nginx

As Nginx only supports FastCGI out of the box, we also need to install fcgiwrap.

On Ubuntu: apt-get install nginx fcgiwrap
On Arch: pacman -S nginx fcgiwrap

Example Nginx config (Ubuntu: /etc/nginx/sites-enabled/default):

server {
    listen   80;
    server_name  localhost;
    access_log  /var/log/nginx/access.log;

    location / {
        root /srv/static;
        autoindex on;
        index index.html index.htm;
    }

    location ~ ^/cgi {
        root /srv/my_cgi_app;
        rewrite ^/cgi/(.*) /$1 break;

        include fastcgi_params;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
        fastcgi_param SCRIPT_FILENAME /srv/my_cgi_app$fastcgi_script_name;
    }
}

Change the root and fastcgi_param lines to a directory containing CGI scripts, e.g. the cgi-bin/ dir in this repository.

If you are a control freak and run fcgiwrap manually, be sure to change fastcgi_pass accordingly. The path listed in the example is the default in Ubuntu when using the out-of-the-box fcgiwrap setup.

cgi's People

Contributors

ruudud 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

Watchers

 avatar  avatar

cgi's Issues

Question about passing arguments using FastCGI + NGINX

I have a question regarding how to set up FastCGI to accept arguments in addition to the script filename. I currently have the same setup listed in the readme on this repo:

    location ~ ^/cgi-bin {
        root /srv/cgi-bin;
        rewrite ^/cgi-bin/(.*) /$1 break;

        include fastcgi_params;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
        fastcgi_param SCRIPT_FILENAME /srv/cgi-bin$fastcgi_script_name;
    }

It works well with a script like scriptname.sh, which would run by browsing to servername.com/cgi-bin/scriptname. What I need to do is to enable arguments coming in over the GET request: servername.com/cgi-bin/scriptname?val1+val2 translated to running bash /srv/cgi-bin/scriptname val1 val2 on the system. How would I configure Nginx and FastCGI to do this?

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.