Fastcgi on nginx » History » Revision 8
Revision 7 (peter rossy, 01/27/2011 12:29 PM) → Revision 8/31 (peter rossy, 01/27/2011 12:31 PM)
h1. Fastcgi on nginx {{toc}} h3. About nginx On paper, nginx is an excellent choice for use as a reverse 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 nginx server and you are ready to go: $ sudo /etc/init.d/nginx restart Order "essay writing":http://www.bookwormlab.com/ [http://www.bookwormlab.com/|essay writing] service or "essay help"|http://www.bestessayhelp.com/ [http://www.bestessayhelp.com/|essay help] service from leading writing assistance agency