标签: fastcgi

fastcgi.conf;与 fastcgi-php.conf 片段相比?

其实两者有什么区别呢?我的网站可以正常工作:

  location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
  }
Run Code Online (Sandbox Code Playgroud)

但是我看到互联网上的一些指南也将片段添加到上面的代码中,例如:

  location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
        include snippets/fastcgi-php.conf;
}
Run Code Online (Sandbox Code Playgroud)

但我看到该片段还包含 fastcgi.conf 。那么为什么我们要添加 include fastcgi.conf 呢?

该代码片段比 fastcgi.conf 还能做什么?

php fastcgi nginx

5
推荐指数
0
解决办法
1124
查看次数

PHP 7 发送响应后继续执行

我正在尝试从函数向客户端发送响应数据并继续执行。我按照下面的代码

ignore_user_abort(true);
set_time_limit(0);

ob_start();
// do initial processing here
echo $response; // send the response
header('Connection: close');
header('Content-Length: '.ob_get_length());
ob_end_flush();
ob_flush();
flush();
// check if fastcgi_finish_request is callable
if (is_callable('fastcgi_finish_request')) {
    fastcgi_finish_request();
}
Run Code Online (Sandbox Code Playgroud)

从问题中得到代码

发送http响应后继续处理php

我得到的只是 200 ok 响应,而不是我回显的数据。

我也需要获取响应数据。我使用的是php7.1。php5和7的使用有什么区别吗?

请帮忙

php fastcgi httpresponse

5
推荐指数
1
解决办法
1576
查看次数

mod_perl2 因大量使用而随机失败,无法恢复

在新的 Ubuntu 服务器上,当超过 8 个客户端连接时,我们的 Apache2 mod_perl2 系统会随机失败。一旦失败,它就无法恢复——所有进一步的快速 CGI 活动都会失败,并且必须重新启动 Apache。该错误非常奇特:它表示它尝试重新加载的标准 Perl 模块中存在语法错误。显然这是错误的,因为它之前已经多次加载它们,并且这些是标准的 Perl 模块。

这是我们得到的 Perl 堆栈跟踪:

    [Thu Oct 04 18:33:09.222314 2018] [perl:error] [pid 11191:tid 139899223140096] [client 10.100.1.61:38632] failed to resolve handler `Che\
mAxonServer': syntax error at /usr/lib/x86_64-linux-gnu/perl/5.22/IO/Handle.pm line 65, near "croak "usage: $class->new()""
syntax error at /usr/lib/x86_64-linux-gnu/perl/5.22/IO/Handle.pm line 73, near "croak "usage: $class->new_from_fd(FD, MODE)""
syntax error at /usr/lib/x86_64-linux-gnu/perl/5.22/IO/Handle.pm line 99, near "croak "IO::Handle: bad open mode: $mode""
syntax error at /usr/lib/x86_64-linux-gnu/perl/5.22/IO/Handle.pm line 104, near "croak 'usage: $io->fdopen(FD, MODE)'" …
Run Code Online (Sandbox Code Playgroud)

apache perl fastcgi mod-perl2

5
推荐指数
0
解决办法
178
查看次数

如何让 nginx 同时处理 fastcgi 请求?

在 ubuntu 18.04 上使用最小的 fastcgi/nginx 配置,看起来 nginx 一次只处理一个 fastcgi 请求。

# nginx configuration
location ~ ^\.cgi$ { 
    # Fastcgi socket
    fastcgi_pass  unix:/var/run/fcgiwrap.socket;

    # Fastcgi parameters, include the standard ones
    include /etc/nginx/fastcgi_params;
}
Run Code Online (Sandbox Code Playgroud)

我通过使用如下所示的 cgi 脚本来演示这一点:

#!/bin/bash

echo "Content-Type: text";
echo;
echo;
sleep 5;
echo Hello world
Run Code Online (Sandbox Code Playgroud)

使用curl 从两个并排的命令提示符访问脚本,您将看到服务器按顺序处理请求。

如何确保 nginx 并行处理 fastcgi 请求?

fastcgi nginx

5
推荐指数
2
解决办法
2356
查看次数

当内容长度在 4013-8092 个字符之间时,Google Cloud Run 网站会超时。到底是怎么回事?

此问题发生在 Nginx 和 PHP-FPM 提供的纯 PHP 文件上。我在使用 Symfony 开发网站时偶然发现了这个问题,但有问题的内容长度范围是 3702-15965 (我想知道为什么它与普通 PHP 不同)。

到目前为止我尝试过的:

  • 超时持续时间为 15 秒,但我尝试将其增加到 300 秒,但仍然超时。所以我猜这是无限循环的事情。
  • 它看起来与资源无关,因为即使内容长度为 500 万个字符它也能工作。
  • 使用不同的字符创建了各种测试,看看是否可以更改有问题的内容长度范围。答案是否定的,我所有的测试范围都保持不变。
  • 我尝试过禁用 gzip。它没有改变长度范围,但响应发生了变化。Gzip 启用响应:“上游请求超时”| Gzip 禁用响应:完全空白

笔记:

  • 我的本地主机上不存在此问题。
  • 很少能正常打开页面。我无法一致地重现这一点。
  • 除了“请求超时”行之外,Nginx、PHP 或 GCR 日志中没有任何错误。

任何帮助表示赞赏。谢谢。

php fastcgi nginx fpm google-cloud-run

5
推荐指数
1
解决办法
2062
查看次数

为什么在 PHP 中的函数 header() 之后调用的函数 http_response_code() 表现得很奇怪?

出色地。我有一个问题http_response_code(),我找不到解释。如果我使用header()before http_response_code(),PHP 将返回由设置的 HTTP 状态header()并忽略任何http_response_code().

例如,我有一个文件:

<?php
header('HTTP/1.1 404 Not Found');
file_put_contents('./log',http_response_code(501).PHP_EOL,FILE_APPEND);
file_put_contents('./log',http_response_code(502).PHP_EOL,FILE_APPEND);
file_put_contents('./log',http_response_code(503).PHP_EOL,FILE_APPEND);

Run Code Online (Sandbox Code Playgroud)

(我用于file_put_contents()防止任何输出,因为有人可以说,这是这个问题的答案)

我使用默认的 php-server (但问题可以用 NGINX 重现):

<?php
header('HTTP/1.1 404 Not Found');
file_put_contents('./log',http_response_code(501).PHP_EOL,FILE_APPEND);
file_put_contents('./log',http_response_code(502).PHP_EOL,FILE_APPEND);
file_put_contents('./log',http_response_code(503).PHP_EOL,FILE_APPEND);

Run Code Online (Sandbox Code Playgroud)

有要求:

php -S localhost:9985
Run Code Online (Sandbox Code Playgroud)

有回应:

HTTP/1.1 404 Not Found
Host: localhost:9958
Date: Wed, 15 Sep 2021 17:20:05 GMT
Connection: close
X-Powered-By: PHP/8.0.10
Content-type: text/html; charset=UTF-8
Run Code Online (Sandbox Code Playgroud)

并且有日志:

404
501
502
Run Code Online (Sandbox Code Playgroud)

响应包括第一行:

HTTP/1.1 404 Not Found 
Run Code Online (Sandbox Code Playgroud)

但我在等待HTTP/1.1 503 Service Unavailable。日志文件包含预期数据,并显示http_response_code …

php fastcgi http-response-codes http-headers

5
推荐指数
1
解决办法
548
查看次数

FCGI htaccess处理程序

我正在尝试在共享托管服务提供商上设置django.我按照http://helpdesk.bluehost.com/index.php/kb/article/000531上的说明进行操作 ,几乎让它正常工作.

我现在面临的问题是流量是通过fcgi文件正确路由的,但文件本身在浏览器中显示为纯文本.如果我在ssh shell中运行./mysite.fcgi,我会得到默认的django欢迎页面.

我的.htaccess是:

AddHandler fastcgi-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ mysite.fcgi/$1 [QSA,L]
Run Code Online (Sandbox Code Playgroud)

和mysite.fcgi:

#!/usr/bin/python2.6
import sys, os
os.environ['DJANGO_SETTINGS_MODULE'] = "icm.settings"

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
Run Code Online (Sandbox Code Playgroud)

谢谢.

django .htaccess shared-hosting fastcgi

4
推荐指数
1
解决办法
3511
查看次数

FastCGI:检索请求标头

我目前正在使用带有Apache和mod_fcgid的FastCGI开发Web C++应用程序.

我正在尝试检索请求的标头,但我没有找到如何执行此操作.经过一些研究,我认为标题位于"FCGX_Request"的属性"envp"中,但它包含环境变量,例如:

REMOTE_ADDR: 192.168.0.50
SERVER_SOFTWARE: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/1.0.0f DAV/2 mod_fcgid/2.3.6
REDIRECT_UNIQUE_ID: TxytP38AAAEAABpcDskAAAAE
FCGI_ROLE: RESPONDER
HTTP_ACCEPT_LANGUAGE: fr
SERVER_SIGNATURE: <address>Apache/2.2.21 [etc.]
Run Code Online (Sandbox Code Playgroud)

这些变量为我提供了有用的信息,但我需要真正的HTTP头,特别是"Cookie".我试图读取"FCGX_Request"的"in"流,但似乎是请求体(POST数据).由于我的应用程序是多线程的,我使用"FCGX_Accept_r()",如下所示:

while(true)
{
    FCGX_Init();
    FCGX_Request* fcgiRequest = new FCGX_Request;
    FCGX_InitRequest(fcgiRequest, 0, 0);

    if(FCGX_Accept_r(fcgiRequest) < 0)
        break;

    Request* request = new Request(fcgiRequest);
    request->process();
}
Run Code Online (Sandbox Code Playgroud)

但实际上,我不使用线程.请求一个接一个地执行.

如何获取请求标头?

谢谢.

c c++ fastcgi

4
推荐指数
1
解决办法
3099
查看次数

无法设置php_value'soap.wsdl_cache_dir'

我有运行Apache 2.2.4和PHP-FPM(FastCGI Process Manager)的VPS服务器(CentOS 6.5).查看php-fpm error_log我发现每个spawn php-fpm子进程都出错了:

WARNING: [pool www] child 24086 said into stderr: "ERROR: Unable to set php_value 'soap.wsdl_cache_dir'"
Run Code Online (Sandbox Code Playgroud)

我找不到关于此警告谷歌搜索的任何信息.有人知道这意味着什么以及如何摆脱这种警告?

更新1:

apache的fastcgi.conf:

User apache                                                                                                                             
Group apache                                                                                                                            

LoadModule fastcgi_module modules/mod_fastcgi.so                                                                                        

<IfModule mod_fastcgi.c>                                                                                                                
    DirectoryIndex index.php index.html index.shtml index.cgi                                                                       
    AddHandler php5-fcgi .php                                                                                                       
    # For monitoring status with e.g. Munin                                                                                         
    <LocationMatch "/(ping|status)">                                                                                                
            SetHandler php5-fcgi-virt                                                                                               
            Action php5-fcgi-virt /php5-fcgi virtual                                                                                
    </LocationMatch>                                                                                                                

    Action php5-fcgi /php5-fcgi                                                                                                     
    Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi                                                                                     
    FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /tmp/php5-fpm.sock -pass-header Authorization                          
</IfModule>

# global FastCgiConfig can be overridden by FastCgiServer options in …
Run Code Online (Sandbox Code Playgroud)

php apache soap fastcgi

4
推荐指数
1
解决办法
9784
查看次数

Perl CGI :: Fast在不发送数据的情况下关闭连接

我正在尝试部署一个CGI::Application通过Nginx使用的Perl应用程序,使用FastCGI在它们之间进行通信.

Nginx不断返回"502 Bad Gateway",错误日志填写如下:

2015/02/03 12:40:03 [错误] 11209#0:*2上游过早关闭连接,同时从上游读取响应头,客户端:10.1.1.23,服务器:www.example.com,请求:"GET/test .fcgi HTTP/1.1",上游:" http://127.0.0.1:5001/test.fcgi ",主持人:"www.example.com"

这是Nginx站点配置:

upstream @perl {
#   I had been trying to use a socket, but I switched to TCP to try WireShark.
#   server unix:/var/run/nginx/my-app.sock;
    server 127.0.0.1:5001;
}

server {
    listen       80;
    listen       443 ssl;

    server_name www.example.com;
    root /home/example/sites/www.example.com;

    location ~* \.fcgi(/|$) {

        fastcgi_split_path_info ^(.+?\.cgi)(/.*)$;
        # (I know that the `if` is old-style, and that `try_files` is better, but that shouldn't affect whether it works or not.) …
Run Code Online (Sandbox Code Playgroud)

perl fastcgi nginx cgi-application

4
推荐指数
1
解决办法
368
查看次数