Commit | Line | Data |
45b58a85 |
1 | =head1 NAME |
2 | |
3 | Catalyst::Manual::Deployment::nginx::FastCGI - Deploying Catalyst with nginx |
4 | |
0191b435 |
5 | =head1 nginx |
45b58a85 |
6 | |
7 | Catalyst runs under nginx via FastCGI in a similar fashion as the lighttpd |
5abded07 |
8 | standalone server. |
45b58a85 |
9 | |
10 | nginx does not have its own internal FastCGI process manager, so you must run |
11 | the FastCGI service separately. |
12 | |
0191b435 |
13 | =head2 Configuration |
45b58a85 |
14 | |
15 | To configure nginx, you must configure the FastCGI parameters and also the |
16 | socket your FastCGI daemon is listening on. It can be either a TCP socket |
17 | or a Unix file socket. |
18 | |
19 | The server configuration block should look roughly like: |
20 | |
21 | server { |
22 | listen $port; |
23 | |
24 | location / { |
25 | fastcgi_param QUERY_STRING $query_string; |
26 | fastcgi_param REQUEST_METHOD $request_method; |
27 | fastcgi_param CONTENT_TYPE $content_type; |
28 | fastcgi_param CONTENT_LENGTH $content_length; |
29 | |
30 | fastcgi_param SCRIPT_NAME /; |
31 | fastcgi_param PATH_INFO $fastcgi_script_name; |
32 | fastcgi_param REQUEST_URI $request_uri; |
33 | fastcgi_param DOCUMENT_URI $document_uri; |
34 | fastcgi_param DOCUMENT_ROOT $document_root; |
35 | fastcgi_param SERVER_PROTOCOL $server_protocol; |
36 | |
37 | fastcgi_param GATEWAY_INTERFACE CGI/1.1; |
38 | fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; |
39 | |
40 | fastcgi_param REMOTE_ADDR $remote_addr; |
41 | fastcgi_param REMOTE_PORT $remote_port; |
42 | fastcgi_param SERVER_ADDR $server_addr; |
43 | fastcgi_param SERVER_PORT $server_port; |
44 | fastcgi_param SERVER_NAME $server_name; |
48bee5f2 |
45 | |
45b58a85 |
46 | # Adjust the socket for your applications! |
47 | fastcgi_pass unix:$docroot/myapp.socket; |
48 | } |
49 | } |
50 | |
51 | It is the standard convention of nginx to include the fastcgi_params in a |
52 | separate file (usually something like C</etc/nginx/fastcgi_params>) and |
53 | simply include that file. |
54 | |
0191b435 |
55 | =head2 Non-root configuration |
45b58a85 |
56 | |
57 | If you properly specify the PATH_INFO and SCRIPT_NAME parameters your |
58 | application will be accessible at any path. The SCRIPT_NAME variable is the |
59 | prefix of your application, and PATH_INFO would be everything in addition. |
60 | |
61 | As an example, if your application is rooted at /myapp, you would configure: |
62 | |
d38b4654 |
63 | rewrite ^/myapp$ /myapp/ permanent; |
64 | location /myapp/ { |
65 | include /etc/nginx/fastcgi_params; |
66 | fastcgi_param SCRIPT_NAME /myapp/; |
67 | fastcgi_param PATH_INFO $fastcgi_script_name; |
09300532 |
68 | fastcgi_pass unix:/tmp/myapp.socket; |
d38b4654 |
69 | } |
45b58a85 |
70 | |
71 | C<$fastcgi_script_name> would be "/myapp/path/of/the/action". Catalyst will |
72 | process this accordingly and setup the application base as expected. |
73 | |
5abded07 |
74 | This behavior is somewhat different from Apache and lighttpd, but is still |
45b58a85 |
75 | functional. |
76 | |
d38b4654 |
77 | Note that the rewrite may not be needed with newer versions of nginx, |
78 | and the paths must be exactly as specified - the trailing slash in the |
09300532 |
79 | location block and the SCRIPT_NAME are important. |
d38b4654 |
80 | |
48bee5f2 |
81 | =head2 SSL |
82 | |
83 | Make sure that nginx passes this to your fastcgi. To ensure this, you need |
84 | the following in your nginx config for the SSL vhost: |
85 | |
86 | fastcgi_param HTTPS on |
87 | |
88 | =head1 MORE INFO |
89 | |
45b58a85 |
90 | For more information on nginx, visit: |
91 | L<http://nginx.net> |
92 | |
93 | =head1 AUTHORS |
94 | |
95 | Catalyst Contributors, see Catalyst.pm |
96 | |
97 | =head1 COPYRIGHT |
98 | |
99 | This library is free software. You can redistribute it and/or modify it under |
100 | the same terms as Perl itself. |
101 | |
102 | =cut |