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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

moakap   2021-03-24 我要评论
想了解在ubuntu下为nginx配置支持cgi脚本的方案的相关内容吗,moakap在本文为您仔细讲解ubuntu配置nginx支持cgi脚本的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:nginx,cgi,配置,nginx,php,cgi,配置,ubuntu,nginx启动脚本,下面大家一起来学习吧。

在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

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们