nginx - 如何为 fcgiwrap 正确设置 DOCUMENT_ROOT 和 SCRIPT_NAME

标签 nginx fastcgi

我有一个简单的脚本 cpuinfo.sh 可以运行并且可执行。

我遇到了一个错误

*224 FastCGI 在标准错误中发送:“无法获取脚本名称,是否设置了 DOCUMENT_ROOT 和 SCRIPT_NAME(或 SCRIPT_FILENAME)并且脚本可执行?”从上游读取响应 header 时,客户端:86.44.146.39,服务器:staging.example.com,请求:“GET/cpuinfo.sh HTTP/1.1”,上游:“fastcgi://unix:/var/run/fcgiwrap.套接字:”,主机:“staging.example.com”

nginx 设置是

location ~ (\.cgi|\.py|\.sh|\.pl|\.lua)$ {
    gzip off;
    autoindex on;
    fastcgi_pass unix:/var/run/fcgiwrap.socket;
    include fastcgi_params;
    fastcgi_param DOCUMENT_ROOT /home/balance/balance-infosystems-web/scripts/;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

我期待 fcgiwrap 执行

/home/balance/balance-infosystems-web/scripts/cpuinfo.sh 

我硬编码了要调试的脚本路径,但仍然遇到同样的错误。

location ~ (\.cgi|\.py|\.sh|\.pl|\.lua)$ {
    gzip off;
    autoindex on;
    fastcgi_pass unix:/var/run/fcgiwrap.socket;
    include fastcgi_params;
    fastcgi_param DOCUMENT_ROOT /home/balance/balance-infosystems-web/scripts/;
    # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param SCRIPT_FILENAME /home/balance/balance-infosystems-web/scripts/cpuinfo.sh;
}

需要在 nginx 服务器配置中进行哪些更改才能正确执行脚本?

最佳答案

我发现 DOCUMENT_ROOT 无法重置。 我通常有远离可公开访问路径的脚本目录。 我知道scripts目录和web目录是同级的所以我试了一下。

location ~ (\.cgi|\.py|\.sh|\.pl|\.lua)$ {
    gzip off;
    autoindex on;
    fastcgi_pass unix:/var/run/fcgiwrap.socket;
    fastcgi_param SCRIPT_FILENAME $document_root/../scripts/$fastcgi_script_name;
    include fastcgi_params ;
}

解决了这个问题。

关于nginx - 如何为 fcgiwrap 正确设置 DOCUMENT_ROOT 和 SCRIPT_NAME,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38828896/

相关文章:

amazon-web-services - 502使用Nginx,Gunicorn和Flask的错误网关

linux - 用Lua分割字符串

html - 使用 Nginx 响应路由器 html5 Pushstae

fastcgi - 我可以像 register_shutdown_function 一样使用 fastcgi_finish_request() 吗?

python - 将 Django 项目移植到 1&1 共享主机 Web 服务器

docker - 静态网站的docker

ssl - Nginx 让加密无法重定向到 www

.htaccess - 在 fastcgi 的 codeigniter 上强制使用 https

python - 我可以同时为 Windows 和 Linux 平台编写 Python Web 应用程序吗?

c++ - FastCGI 通过 C : FCGX_Accept_r occasionally perform "Connection reset..."