服务器 
首页 > 服务器 > 浏览文章

在ubuntu下为nginx配置支持cgi脚本的方案

(编辑:jimmy 日期: 2024/5/9 浏览:3 次 )

在nginx下支持cgi脚本于支持node类似的,只要在nginx直接做个转发,转发到对应的cgi套接字就好。

使用Fcgiwrap

Fcgiqwrap是另外一个CGI封装库,跟Simple CGI类似。

安装fcgiwrap

apt-get install fcgiwrap

安装以后fcgiwrap默认已经启动,对应的套接字是 /var/run/fcgiwrap.socket 。如果没有启动,使用 /etc/init.d/fcgiwrap 手动启动。

配置nginx的vhost文件

在要支持cgi脚本的路径下,添加对应的server配置。比如所有的cgi都在cgi-bin路径下:

server {
[...]
  location /cgi-bin/ {
   # Disable gzip (it makes scripts feel slower since they have to complete
   # before getting gzipped)
   gzip off;
   # Set the root to /usr/lib (inside this location this means that we are
   # giving access to the files under /usr/lib/cgi-bin)
   root /var/www/www.example.com;
   # Fastcgi socket
   fastcgi_pass unix:/var/run/fcgiwrap.socket;
   # Fastcgi parameters, include the standard ones
   include /etc/nginx/fastcgi_params;
   # Adjust non standard parameters (SCRIPT_FILENAME)
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  }
[...]
}

重新加载nginx:

nginx -s reload

测试

在cgi-bin下创建hello-world.cgi

#!/usr/bin/perl -w
   # Tell perl to send a html header.
   # So your browser gets the output
   # rather then <stdout>(command line
   # on the server.)
print "Content-type: text/html\n\n";
   # print your basic html tags.
   # and the content of them.
print "<html><head><title>Hello World!! </title></head>\n";
print "<body><h1>Hello world</h1></body></html>\n";

设置执行权限

chmod 755 /var/www/www.example.com/cgi-bin/hello_world.cgi

在浏览器打开对应脚本,即可看到已经配置成功! http://www.example.com/cgi-bin/hello_world.cgi

上一篇:Centos7下编译安装配置Nginx+PHP+MySql环境
下一篇:Centos 7开启网卡自动获取IP的详细方法
一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网