Project

General

Profile

Fastcgi on nginx » History » Version 7

peter rossy, 01/27/2011 12:29 PM

1 1 Pieter Libin
h1. Fastcgi on nginx
2
3
{{toc}}
4
5
6
h3. About nginx 
7
8 3 Koen Deforche
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).
9 1 Pieter Libin
10
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.
11
12
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.
13
14
15
h3. Ubuntu config 
16
17
* Installing nginx and spawn-fcgi (which comes with lighttpd):
18
19
<pre>
20
 $ sudo apt-get install nginx lighttpd
21
</pre>
22
23
* Start your application (linked against wtfcgi) using spawn-fcgi. Spawn-fcgi wraps the FastCGI application to listen to a socket or network connection.
24
25
<pre>
26
 $ spawn-fcgi -n -f ../../build/examples/hello/hello.wt -a 0.0.0.0 -p 9091
27
</pre>
28
29
* Edit your nginx configuration to redirect a particular URL to your application (replace all occurences of /hello.wt with the path for your application!) :
30
31
<pre>
32
        location /hello.wt {
33
                fastcgi_pass   127.0.0.1:9091;
34
 
35
                fastcgi_param  QUERY_STRING       $query_string;
36
                fastcgi_param  REQUEST_METHOD     $request_method;
37
                fastcgi_param  CONTENT_TYPE       $content_type;
38
                fastcgi_param  CONTENT_LENGTH     $content_length;
39
 
40
                if ($document_uri ~ "^/hello.wt/(.*)") {
41
                        set $apache_path_info /$1;
42
                }
43
 
44
                fastcgi_param  SCRIPT_NAME        /hello.wt;
45
                fastcgi_param  PATH_INFO          $apache_path_info;
46
                fastcgi_param  REQUEST_URI        $request_uri;
47
                fastcgi_param  DOCUMENT_URI       $document_uri;
48
                fastcgi_param  DOCUMENT_ROOT      $document_root;
49
                fastcgi_param  SERVER_PROTOCOL    $server_protocol;
50
 
51
                fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
52
                fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
53
 
54
                fastcgi_param  REMOTE_ADDR        $remote_addr;
55
                fastcgi_param  REMOTE_PORT        $remote_port;
56
                fastcgi_param  SERVER_ADDR        $server_addr;
57
                fastcgi_param  SERVER_PORT        $server_port;
58
                fastcgi_param  SERVER_NAME        $server_name;
59
        }
60
</pre>
61
62 3 Koen Deforche
* Reload (or restart) your nginx server and you are ready to go:
63 1 Pieter Libin
64
 $ sudo /etc/init.d/nginx restart
65 4 peter rossy
66 7 peter rossy
Order [http://www.bookwormlab.com/|essay writing] service or [http://www.bestessayhelp.com/|essay help] service from leading writing assistance agency