Project

General

Profile

Fastcgi on nginx » History » Version 30

richard jones, 06/26/2017 01:41 AM

1 30 richard jones
h1. Fastcgi on nginx
2 1 Pieter Libin
3
{{toc}}
4
5
6 30 richard jones
h3. About nginx 
7 1 Pieter Libin
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 30 richard jones
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 1 Pieter Libin
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 27 Checheta Yan
15 30 richard jones
h3. Ubuntu config 
16 1 Pieter Libin
17
* Installing nginx and spawn-fcgi (which comes with lighttpd):
18
19
<pre>
20 20 Nuika Sanders
 $ sudo apt-get install nginx lighttpd
21 1 Pieter Libin
</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 30 richard jones
* 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 1 Pieter Libin
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 15 Andy Z
                fastcgi_param  SERVER_PORT        $server_port;
58
                fastcgi_param  SERVER_NAME        $server_name;
59
        }
60
</pre>
61 16 Laurence Withers
62
* Reload (or restart) your nginx server and you are ready to go:
63
64
 $ sudo /etc/init.d/nginx restart
65
66 30 richard jones
Order "essay writing":http://www.bookwormlab.com/ service or "essay help":http://www.bestessayhelp.com/ service from leading writing assistance agency
67
Интернет-магазин где можна "купить косметику и аксессуары":http://www.kriss.com.ua/, все для женщин и девушек.
68
"Купить пакеты, пленку, упаковку":http://www.packit.com.ua/ от производителя Packit