ubuntu设置全局脚本_在ubuntu下为nginx配置支持cgi脚本的方案

在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 (command line

# on the server.)

print "Content-type: text/html\n\n";

# print your basic html tags.

# and the content of them.

print "

Hello World!! \n";

print "

Hello world

\n";

设置执行权限

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值