如何在nginx

问题描述 投票:0回答:7

你有什么想法吗?我正在运行Centos5 我找到了一些解决方案here

,但是我无法将其与this perl脚本

的代码集成 我在珀尔完全为零,请帮助我 谢谢

NGINX没有本机CGI支持(它支持FastCGI)。这样做的典型解决方案是将您的perl脚本作为fastcgi流程运行,并编辑nginx配置文件以将请求重新指定到FastCGI进程。如果您要做的就是运行CGI脚本,这是一个很复杂的解决方案。 您必须使用nginx作为此解决方案吗?如果您要做的就是执行一些PERL CGI脚本,请考虑使用Apache或LightTPD随附CGI模块,这些模块将本地处理您的CGI脚本,并且不需要将脚本作为单独的过程运行。为此,您需要安装Web服务器并编辑Web服务器配置文件以加载CGI模块。对于LightTPD,您需要在配置文件中添加一行以启用CGI文件的处理。然后将CGI文件放入CGI-bin文件夹中。

安装在不同端口上运行的另一台Web服务器(Apache,LightTPD)。然后使用Nginx代理您的CGI请求。
perl nginx cgi centos
7个回答
26
投票
上安装Web服务器后,您只需要将其添加到Nginx配置中

location /cgi-bin { proxy_pass http://127.0.0.1:8080; }

查看

NGINX位置指令解释了

19
投票

NGINX是Web服务器。您需要将应用程序服务器用于任务,例如

UWSGI

。它可以使用其本机非常有效的二进制界面与NGINX对话。

I发现使用FastCGI的黑客比运行另一台Web服务器要好一些。 http://nginxlibrary.com/perl-fastcgi/


13
投票

i发现了这一点:https://github.com/ruudud/cgithe说:


6
投票

On Ubuntu: apt-get install nginx fcgiwrap On Arch: pacman -S nginx fcgiwrap Example Nginx config (Ubuntu: /etc/nginx/sites-enabled/default): server { listen 80; server_name localhost; access_log /var/log/nginx/access.log; location / { root /srv/static; autoindex on; index index.html index.htm; } location ~ ^/cgi { root /srv/my_cgi_app; rewrite ^/cgi/(.*) /$1 break; include fastcgi_params; fastcgi_pass unix:/var/run/fcgiwrap.socket; fastcgi_param SCRIPT_FILENAME /srv/my_cgi_app$fastcgi_script_name; } } 将根和fastcgi_param行更改为包含CGI脚本的目录,例如此存储库中的CGI-bin/ dir。

如果您是一个控制怪胎并手动运行FCGIWRAP,请确保相应地更改FastCGI_Pass。该示例中列出的路径是使用开箱即用的FCGIWRAP设置时的Ubuntu中的默认路径。

6
投票
我要尝试一下。

基于布拉德的回答,简化和现代化,并为CGI提供了AWSTATS的示例:

location ~ ^/cgi-bin/awstats\.pl { root /usr/lib/cgi-bin; rewrite ^/cgi-bin/(.*) /$1 break; include fastcgi.conf; fastcgi_pass unix:/run/fcgiwrap.socket; }

您需要安装

fcgiwrap
软件包。
    

如果您有一个专用文件夹,则使用fastcgi-wrap的配置变得更加简单:

sudo apt-get install fcgiwrap

location /cgi-bin { gzip off; fastcgi_pass unix:/var/run/fcgiwrap.socket; include /etc/nginx/fastcgi_params; }

然后例如

1
投票
/var/www/html/cgi-bin/hello.sh

#!/bin/bash echo -e "Content-type:text/html\n" echo "<pre>" env # Show available environment vars, including QUERY_STRING etc
    

我等待CGI支持10年而没有任何幸运。
因此,最后我自己为Nginx制作了CGI插件。
https://github.com/pjincz/nginx-cgi


0
投票
插件安装后,只需打开CGI支持:

location /cgi-bin { cgi on; }
    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.