4

Is there any webserver that supports CGI (not FastCGI/Rack/WSGI) and that is easy to setup? (lightweight and portable if possible, just need to copy the binary to another similar machine)

So I'll just need to put some CGI scripts there, and then when I visit that script using a browser, the script gets exectured and displayed in the browser.

OS: Linux

  • 2
    Take a look at XAMPP apachefriends.org. It has a portable version too. – Cornelius May 8 '14 at 7:58
  • sorry, I just edit my question, I prefer lightweight too, XAMPP just too big for me – Kokizzu May 8 '14 at 7:59
  • 1
    It is not portable, but it is lightweight: nginx tautvidas.com/blog/2012/01/… – Cornelius May 8 '14 at 8:26
  • umm.. thats FastCGI not CGI.. thanks anyway.. – Kokizzu May 8 '14 at 8:39
  • 1
    Yes, Nginx counts as one of its (security) features that it cannot run CGI. Feature or not, few people care, since FastCGI typically far preferred over CGI. – Paul Draper May 8 '14 at 8:42
2

I've used Acme Labs' thhtpd - easy to set up, fast and supports CGI.

Most recently I put it one some Raspberry Pis.

It's a single binary, when you launch it you give it the name of a config file.

2

busybox can be built with http and cgi modules.

Let me quote the project's description:

BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc. The utilities in BusyBox generally have fewer options than their full-featured GNU cousins; however, the options that are included provide the expected functionality and behave very much like their GNU counterparts. BusyBox provides a fairly complete environment for any small or embedded system.

BusyBox has been written with size-optimization and limited resources in mind. It is also extremely modular so you can easily include or exclude commands (or features) at compile time. This makes it easy to customize your embedded systems. To create a working system, just add some device nodes in /dev, a few configuration files in /etc, and a Linux kernel.

1

uWSGI with CGI (only requires Python)

Install using:

curl http://uwsgi.it/install | bash -s cgi /tmp/uwsgi

create a setup configuration so you can run it without too many arguments, for example test.ini

[uwsgi]
http = :8081
http-modifier1 = 9
#uid = 
#gid =
check-static = ./www
static-skip-ext = .php
static-skip-ext = .rb
static-skip-ext = .py 
static-skip-ext = .lua
static-index = index.html
async = 16
ugreen = true
socket = 127.0.0.1:9000
cgi = ./cgi
cgi-allowed-ext = .php
cgi-allowed-ext = .rb
cgi-allowed-ext = .py
cgi-allowed-ext = .lua
cgi-index = index.rb

create a testing script, for example ./cgi/test.rb

#!/usr/bin/env ruby    
require 'cgi'    
cgi = CGI.new
puts cgi.header
puts '<html><body>ENV: <ol>'
ENV.each do |k,v|
  puts "<li><b>#{k}</b> #{v}</li>"
end
puts '</ol>POST: <ol>'
cgi.params.each do |k,v|
  puts "<li><b>#{k}</b> #{v}</li>"
end
puts '</ol></body></html>'

start the server using:

./uwsgi test.ini

test it using browser or curl:

curl -d 'test2=2' localhost:8081/test.rb?test=1
  • curl http://.. | bash allows anyone in your local network to install arbitrary software on your machine. – phihag Mar 30 '17 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.