仅将 URI 中的第一个路径元素与 CGI 可执行文件相匹配的正确 nginx 位置规则是什么?
我正在使用为 apache cgi-bin 和 nginx 设计的 FreePascal Web 模块。
CGI 本身称为 spidersample.cgi 并包含诸如 hello、bye 等模块。
使用 Apache,当调用 spidersample.cgi/hello 时, spidersample.cgi 被执行,并将控制权传递给它包含的 hello 子例程。
使用nginx而不是执行spidersample.cgi,它将spidersample.cgi/hello视为spidersample.cgi<中的hello文件/strong> 目录,并返回 404 错误,因为没有这样的目录。
我怀疑这是一个很容易解决的问题,配置文件中有一些重写规则,它发布在下面。
===============================================
服务器 { 听8118; 服务器名称本地主机; access_log /var/log/nginx/sysman_access.log; 索引index.html; 根 /home/rchurch/Data/Lazarus/CgiApps;
location ~ \.cgi$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/tmp/sysman_cgi.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_n$
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
}
}
===================================================== =================
I am using a FreePascal web module designed for apache cgi-bin with nginx.
The CGI itself is called spidersample.cgi and contains modules such as hello, bye etc.
With Apache when spidersample.cgi/hello is called, spidersample.cgi gets executed, and passes control to the hello subroutine it contains.
With nginx instead of executing spidersample.cgi it treats spidersample.cgi/hello as meaning a hello file in a spidersample.cgi directory, and returns with a 404 error as there is no such directory.
I suspect it is an easily fixed problem with some rewrite rules in the configuration file and it is posted below.
=============================================
server {
listen 8118;
server_name localhost;
access_log /var/log/nginx/sysman_access.log;
index index.html;
root /home/rchurch/Data/Lazarus/CgiApps;
location ~ \.cgi$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/tmp/sysman_cgi.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_n$
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
}
}
==================================================================
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
location ~ .cgi$ 将匹配 Spidersample.cgi //$ 表示行尾
Spidersample.cgi/hello 匹配 location ~ (.+)cgi/hello 或 (.+)cgi(.*)
location ~ .cgi$ will match spidersample.cgi //$ means end of the line
spidersample.cgi/hello match location ~ (.+)cgi/hello or (.+)cgi(.*)