H2CO3/Sparkling — pull request #22 by sfan5 (2014-03-21 18:44:38+00:00)
Title: FastCGI support

Adds FastCGI support, below is my example configuration.

test.spn:
```c
// example CGI script
printf("Content-Type: text/html\r\n\r\n");
print("

Hello World!

");
print("

Hello World from Sparkling!

");
print("Sparkling on github
");
print("Some environment variables follow:
");
print("

");
var vars = {
"CONTENT_TYPE": 1,
"GATEWAY_INTERFACE": 1,
"DOCUMENT_URI": 1,
"REMOTE_ADDR": 1,
"QUERY_STRING": 1,
"FCGI_ROLE": 1,
"DOCUMENT_ROOT": 1,
"REMOTE_PORT": 1,
"HTTP_USER_AGENT": 1,
"HTTP_ACCEPT": 1,
"CONTENT_LENGTH": 1,
"SCRIPT_FILENAME": 1,
"HTTP_HOST": 1,
"REQUEST_URI": 1,
"SERVER_SOFTWARE": 1,
"HTTP_CONNECTION": 1,
"HTTP_ACCEPT_LANGUAGE": 1,
"SERVER_PROTOCOL": 1,
"HTTP_ACCEPT_ENCODING": 1,
"REDIRECT_STATUS": 1,
"REQUEST_METHOD": 1,
"SERVER_ADDR": 1,
"SERVER_PORT": 1,
"SCRIPT_NAME": 1,
"SERVER_NAME": 1,
"REMOTE_HOST": 1,
"HTTPS": 1,
"HTTP_REFERER": 1
};

foreach(vars, function(key, val, arr) {
if(getenv(key) != nil) {
printf("%s = %s\n", key, getenv(key));
} else {
printf("%s not defined\n", key);
}
});
print("

");
```
nginx.conf:
```conf
# pass the Sparkling scripts to FastCGI server listening on 127.0.0.1:9001
#
location ~ \.spn$ {
root html;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.spn;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
```
FastCGI is started using: /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9001 -- spn-fcgi

Link to working example: http://sfan5.duckdns.org:8080/test.spn