The service os-fcgi implements the FastCGI protocol, which is supported by all major webservers, including apache and NGINX.

To configure NGINX to work alongside with os-fcgi, we simply have to add fastcgi_pass; into the desired location.

By default, os-fcgi uses port 9000. However, you can alter this by editing /etc/os-fcgi/conf.os. Make sure you make the appropriate changes to the NGINX config as well.

Example configuration for NGINX

Typically, the configuration file of the site is located at /etc/nginx/sites-enabled/.

server {
    listen          80;
    root            /home/myuser/;
    error_log       /var/log/nginx/;
    access_log      off;
    location ~ /\.ht {
        deny all;
    location ~ /\.git {
        deny all;
    location / {
        try_files $uri $uri/ /index.osh /index.os;
    location ~* \.(jpg|jpeg|png|gif|swf|flv|mp4|mov|avi|wmv|m4v|mkv|ico|js|css|txt)$ {
        access_log off;
        expires 7d;
    charset utf-8;
    location ~ ^.+\.osh? {
        fastcgi_split_path_info ^(.+?\.osh?)(.*)$;
        fastcgi_pass      ;
        fastcgi_index               index.osh;
        include                     fastcgi_params;
        fastcgi_intercept_errors    on;
        fastcgi_ignore_client_abort on;
        fastcgi_read_timeout        360;

The fastcgi_params file

Now we will adjust /etc/nginx/fastcgi_params so that parameters are correclty passed to os-fcgi.

fastcgi_param   QUERY_STRING            $query_string;
fastcgi_param   REQUEST_METHOD          $request_method;
fastcgi_param   CONTENT_TYPE            $content_type;
fastcgi_param   CONTENT_LENGTH          $content_length;

# fastcgi_param   SCRIPT_FILENAME         $request_filename;
fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;
fastcgi_param   SCRIPT_NAME             $fastcgi_script_name;
fastcgi_param   REQUEST_URI             $request_uri;
fastcgi_param   DOCUMENT_URI            $document_uri;
fastcgi_param   DOCUMENT_ROOT           $document_root;
fastcgi_param   SERVER_PROTOCOL         $server_protocol;
fastcgi_param   HTTP_REFERER	  		$http_referer;

fastcgi_param   GATEWAY_INTERFACE       CGI/1.1;
fastcgi_param   SERVER_SOFTWARE         nginx/$nginx_version;

fastcgi_param   REMOTE_ADDR             $remote_addr;
fastcgi_param   REMOTE_PORT             $remote_port;
fastcgi_param   SERVER_ADDR             $server_addr;
fastcgi_param   SERVER_PORT             $server_port;
fastcgi_param   SERVER_NAME             $server_name;

fastcgi_param   REDIRECT_STATUS         200;

That's it. Now all you need to do is restart NGINX to make the changes appear:

service nginx restart

Fork me on GitHub