2024-09-04

itml2md

(sph scgi)

#(library-short-description (sph scgi))

see also scgi specification a program using this interface starts once, listens on a socket, and will be able to process an arbitrary number of requests with a custom set procedure this differs from cgi scripts which start completely anew for each single request web servers that support scgi are for example nginx and apache it is similar to fastcgi, but much less complicated part of #(link-c-one ("sph-lib" "overview"))

features

automatic socket creation if no socket is passed supports all types of sockets that are supported by guile uses the tested #(link-c-one ("server" "sph-lib")) and #(link-c-one ("thread-pool" "sph-lib")) libraries to automatically distribute load to multiple available cores

usage example

(scgi-handle-requests
  (lambda (headers client) (display "hello" client)))

nginx example

nginx can be used as a reverse proxy to translate http/https requests to scgi requests passed on a socket to the scgi application the following is a configuration, for example for "/etc/nginx.conf". the file "scgi_params" should come with nginx and be already set-up

server {
  root /srv/http/test-server;
  location / {
    include scgi_params;
    scgi_pass unix:/tmp/1000/test-application-socket;
  }

scgi_params

this file contains nginx directives to configure the values from the http client request that are passed on to the scgi server application nginx should have a default scgi_params file, and there may be no need to care much about this file the following is a customized example (usually the variables are written in uppercase) to show what the contents look like. the only required parameter is "SCGI 1"

scgi_pass_request_headers off;
scgi_param SCGI 1;
scgi_param request_method $request_method;
scgi_param remote_addr $remote_addr;
scgi_param http_cookie $http_cookie;
scgi_param user_agent $http_user_agent;
scgi_param if_modified_since $http_if_modified_since;
scgi_param content_type $http_content_type;
scgi_param request_uri $request_uri;
scgi_param https $https;
#(library-documentation (sph scgi))