[英]Running CGI scripts on NGINX
我知道已经问过这个问题,但是没有一个明确的答案( 如何在Nginx上运行CGI脚本 )对我有帮助。 就我而言,我已经使用源代码安装了NGINX,并修复了.config文件,以便可以使用FASTCGI成功读取.php文件。 但是,在运行CGI脚本时,我遇到了很多问题。 我知道我已经安装并设置了FAST CGI,所以我应该将这些.cgi文件命名为.fcgi吗? 还是我应该为.cgi文件添加某种方式,以使其知道它可以与FAST CGI一起使用? 我试图绕开nginf.conf文件以包含.fcgi,现在看起来像这样:
worker_processes 2;
pid logs/nginx.pid;
error_log syslog:server=unix:/dev/log,facility=local7,tag=nginx,severity=error;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
access_log syslog:server=unix:/dev/log,facility=local7,tag=nginx,severity=info combined;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
root /home/parallels/Downloads/user_name/nginx/html;
location / {
index index.html index.htm new.html;
autoindex on;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
include fastcgi_params;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~ \.pl|fcgi$ {
try_files $uri =404;
gzip off;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.pl;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
但是,每当我运行.fcgi脚本(例如
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<html><body>Hello, world.</body></html>";
我看到一个看起来像这样的屏幕:
我敢肯定这是不正常的。 我应该只是看到Hello, world.
在我的屏幕上,不是所有的代码也是如此。 请让我知道我的想法是否确实错误,这应该是正确的输出。
此外,如果我将其作为files.fcgi
文件,请注意:
#!/usr/bin/perl
my $output = `ls`;
print $output
运行类似的操作会返回.fcgi文件所在目录中所有文件的列表。无论如何,我可以在Web浏览器上显示此文件吗? 在线查看示例,似乎人们已经能够在他们的浏览器上运行file.fcgi
并查看shell命令的输出(这使我相信我做错了,因为当我在命令上运行它时,行中列出了所有文件,但是在浏览器上,它只是打印出我的代码)。 假设我做错了什么,谁知道我可能做错了什么。 如果您需要更多信息,请告诉我!
谢谢你,有一个美好的一天!
nginx不支持CGI脚本,也不能单独启动FastCGI脚本-它只能连接到已经在运行的FastCGI进程。
如果要运行CGI脚本,请使用支持它们的Web服务器,例如Apache。 尽管有一些解决方法,但在此阶段它们只会使您感到困惑。
搜索“ fastcgi包装器”以找到各种程序,这些程序旨在弥合不喜欢产生请求处理过程的“现代” Web服务器与传统CGI程序之间的鸿沟。
[nginx ] one socket [wrapper ] ,-- forks a single subprocess
[runs ] == connection ==> [also runs ] ---- running your CGI program
[continuously] per request [continuously] `-- for each request
标准CGI API是“针对每个请求,服务器使用env vars调用您的程序来描述该请求,并使用stdin上的主体(如果有)调用您的程序,并且您的程序应在stdout并退出时发出响应”,fcgi API希望您的程序能够持续运行并处理套接字上传递给它的请求-这样,它实际上更像是服务器。 参见http://en.wikipedia.org/wiki/FastCGI
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.