个人工具
104.160.18.24
该IP地址的讨论
登录
查看“UbuntuHelp:FcgiWrap”的源代码 - Ubuntu中文
UbuntuHelp
讨论
查看源代码
历史
搜索
导航
首页
最近更改
随机页面
页面分类
帮助
编辑
编辑指南
沙盒
新闻动态
字词处理
工具
链入页面
相关更改
特殊页面
页面信息
查看“UbuntuHelp:FcgiWrap”的源代码
来自Ubuntu中文
←
UbuntuHelp:FcgiWrap
跳转至:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{{From|https://help.ubuntu.com/community/FcgiWrap}} {{Languages|UbuntuHelp:FcgiWrap}} == Introduction == [http://nginx.localdomain.pl/wiki/FcgiWrap fcgiwrap] is a simple server for running CGI applications over FastCGI. It hopes to provide clean CGI support to Nginx (and other web servers that may need it). [[UbuntuHelp:fcgiwrap|fcgiwrap]] can be used together with [[UbuntuHelp:nGinx|nGinx]] to serve [[UbuntuHelp:CGI|CGI]] or [[UbuntuHelp:Perl|Perl]] scripts (.cgi). === Installation === There's no package for fcgiwrap so we're going to compile it from sources. To be able to compile it we'll need <code><nowiki>make</nowiki></code>, <code><nowiki>gcc</nowiki></code> and <code><nowiki>libfcgi-dev</nowiki></code>. You can install these packages like this: <pre><nowiki> sudo apt-get install build-essential libfcgi-dev </nowiki></pre> Next we need to download and compile the latest version of fcgiwrap which is located in [http://github.com/gnosek/fcgiwrap/ Grzegorz Nosek's Github] <pre><nowiki> mkdir /tmp/fcgiwrap cd /tmp/fcgiwrap wget http://github.com/gnosek/fcgiwrap/tarball/master -O fcgiwrap.tar.gz tar xf fcgiwrap.tar.gz make </nowiki></pre> Once the compilation is finished just copy the resulted binary to your <code><nowiki>/usr/bin</nowiki></code> directory. Don't forget to check if it is executable! <pre><nowiki> cp /tmp/fcgiwrap/fcgiwrap/fcgiwrap /usr/bin chmod +x /usr/bin/usr/bin </nowiki></pre> The installation is finished. === Configuration === To be able to spawn a fcgi socket, we are going to write a script for it and than add a init script to <code><nowiki>/etc/init.d/</nowiki></code> to automatize this process. Here is the <code><nowiki>spawn-fcgi</nowiki></code> script which will create a socket to pass .cgi to it: <pre><nowiki> cat > /usr/bin/spawn-fcgi #!/usr/bin/perl use strict; use warnings FATAL => qw( all ); use IO::Socket::UNIX; my $bin_path = '/usr/bin/fcgiwrap'; my $socket_path = $ARGV[0] || '/tmp/cgi.sock'; my $num_children = $ARGV[1] || 1; close STDIN; unlink $socket_path; my $socket = IO::Socket::UNIX->new( Local => $socket_path, Listen => 100, ); die "Cannot create socket at $socket_path: $!\n" unless $socket; for (1 .. $num_children) { my $pid = fork; die "Cannot fork: $!" unless defined $pid; next if $pid; exec $bin_path; die "Failed to exec $bin_path: $!\n"; } </nowiki></pre> Don't forget to make it executable: <pre><nowiki> chmod +x /usr/bin/spawn-fcgi </nowiki></pre> The above script will be used to automatize the re-spawning of the FastCGI socket: <pre><nowiki> cat > /etc/init.d/spawn-fcgi #!/bin/bash C_SCRIPT=/usr/bin/spawn-fcgi USER=www-data GROUP=www-data RETVAL=0 case "$1" in start) echo "Starting fastcgi" sudo -u $USER $C_SCRIPT chown $USER:$GROUP /tmp/cgi.sock RETVAL=$? ;; stop) echo "Stopping fastcgi" killall -9 fcgiwrap RETVAL=$? ;; restart) echo "Restarting fastcgi" killall -9 fcgiwrap $sudo -u $USER $C_SCRIPT RETVAL=$? ;; *) echo "Usage: $0 {start|stop|restart}" exit 1 ;; esac exit $RETVAL </nowiki></pre> Set the permissions to make the script executable and install the init script: <pre><nowiki> chmod +x /etc/init.d/spawn-fcgi update-rc.d spawn-fcgi defaults </nowiki></pre> Now we can start and stop the script using <code><nowiki>invoke-rc.d</nowiki></code>: <pre><nowiki> invoke-rc.d spawn-fcgi start invoke-rc.d spawn-fcgi stop </nowiki></pre> After you start the <code><nowiki>spawn-fcgi</nowiki></code> you should see a new file in <code><nowiki>/tmp</nowiki></code> folder with the name <code><nowiki>cgi.sock</nowiki></code>. That file is our socket to pass .cgi scripts to. === Configuring nGinx === Create the configuration file for nGinx to use [[UbuntuHelp:fastCGI|fastCGI]]: <pre><nowiki> cat > /etc/nginx/fastcgi_params fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; 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; 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; fastcgi_param REMOTE_USER $remote_user; </nowiki></pre> The created above file now can be added to nGinx vhosts to allow them using <code><nowiki>fcgiwrap</nowiki></code>. Here's an example of such a vhost file configured to work for [[UbuntuHelp:Namazu|Namazu]]: <pre><nowiki> server { listen 80; server_name localhost; access_log /var/log/nginx/access.log; location / { root /storage/archive; autoindex on; index index.html index.htm; } location ~ \.cgi$ { root /storage/archive/cgi-bin; rewrite ^/cgi-bin/(.*)\.cgi /$1.cgi break; include /etc/nginx/fastcgi_params; fastcgi_pass unix:/tmp/cgi.sock; fastcgi_param SCRIPT_FILENAME /storage/archive/cgi-bin$fastcgi_script_name; } } </nowiki></pre> [[category:UbuntuHelp]]
该页面使用的模板:
模板:From
(
查看源代码
)
模板:Languages
(
查看源代码
)(受保护)
模板:Languages/Lang
(
查看源代码
)(受保护)
返回至
UbuntuHelp:FcgiWrap
。