Project

General

Profile

Fastcgi on nginx » History » Revision 3

Revision 2 (Bonnet Matheo, 05/20/2010 07:22 PM) → Revision 3/31 (Koen Deforche, 05/27/2010 07:05 AM)

h1. Fastcgi on nginx 

 {{toc}} 


 h3. About nginx  

 On paper, nginx is an excellent choice for use as a reverse "custom writing":http://custom-paper-writing.com/ proxy (together with wthttpd), or for deploying Wt applications using FastCGI, especially if you are using server-initiated updates (server push). 

 The reason is that nginx, like wthttpd, is completely based on asynchronous I/O, and therefore scales easily to many open connections (unlike other web servers such as apache, lighttpd, etc...). Server-initiated updates use an open connection for every web client. 

 We have tested nginx succesfully for both its use as a reverse proxy or for FastCGI deployment of Wt applications. Its FastCGI implementation is a bit clumsy, but newer versions of nginx (>= 0.7.31) than the version currently available in ubuntu should improve on that. 


 h3. Ubuntu config  

 * Installing nginx and spawn-fcgi (which comes with lighttpd): 

 <pre> 
  $ sudo apt-get install nginx lighttpd 
 </pre> 

 * Start your application (linked against wtfcgi) using spawn-fcgi. Spawn-fcgi wraps the FastCGI application to listen to a socket or network connection. 

 <pre> 
  $ spawn-fcgi -n -f ../../build/examples/hello/hello.wt -a 0.0.0.0 -p 9091 
 </pre> 

 * Edit your nginx configuration to redirect a particular URL to your application (replace all occurences of /hello.wt with the path for your application!) : 

 <pre> 
         location /hello.wt { 
                 fastcgi_pass     127.0.0.1:9091; 
 
                 fastcgi_param    QUERY_STRING         $query_string; 
                 fastcgi_param    REQUEST_METHOD       $request_method; 
                 fastcgi_param    CONTENT_TYPE         $content_type; 
                 fastcgi_param    CONTENT_LENGTH       $content_length; 
 
                 if ($document_uri ~ "^/hello.wt/(.*)") { 
                         set $apache_path_info /$1; 
                 } 
 
                 fastcgi_param    SCRIPT_NAME          /hello.wt; 
                 fastcgi_param    PATH_INFO            $apache_path_info; 
                 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    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; 
         } 
 </pre> 

 * Reload (or restart) your "Essays":http://custom-essay-writing-service.org/index.php nginx server and you are ready to go: 

  $ sudo /etc/init.d/nginx restart