FastCGI and Nginx - HTTP status return

I have a custom FastCGI application for Nginx, and I'm struggling to get Nginx to return nothing but a 200 status code.

I tried the following:

  • Setting fast_cgi_intercept_errors.

  • Return codes through ApplicationStatusin EndRequest.

  • Return errors in a StdError stream.

  • Submit any of the following headers:

    • "Status: 404 not found"

    • "HTTP / 1.1 404 not found"

    • "X-PHP-Response-Code: 404"

    • "Status: 404 not found;"

    • "HTTP / 1.1 404 not found;"

    • "X-PHP-Response-Code: 404;"

Any help would be great, I am very stuck.

+4
source share
2 answers

, 404 fcgi ++.

#include <iostream>
#include "fcgio.h"

using namespace std;

int main(void)
{
  streambuf * cin_streambuf = cin.rdbuf();
  streambuf * cout_streambuf = cout.rdbuf();
  streambuf * cerr_streambuf = cerr.rdbuf();

  FCGX_Request request;

  FCGX_Init();
  FCGX_InitRequest(&request, 0, 0);

  while (FCGX_Accept_r(&request) == 0)
  {
    fcgi_streambuf cin_fcgi_streambuf(request.in);
    fcgi_streambuf cout_fcgi_streambuf(request.out);
    fcgi_streambuf cerr_fcgi_streambuf(request.err);

    cin.rdbuf(&cin_fcgi_streambuf);
    cout.rdbuf(&cout_fcgi_streambuf);
    cerr.rdbuf(&cerr_fcgi_streambuf);

    cout << "Status: 404\r\n"
         << "Content-type: text/html\r\n"
         << "\r\n"
         << "<html><body>Not Found</body></html>\n";
  }

  cin.rdbuf(cin_streambuf);
  cout.rdbuf(cout_streambuf);
  cerr.rdbuf(cerr_streambuf);

  return 0;
}
+1

nginx "HTTP/1.1 304 Not Modified\r\n".

nginx ( ) Status.

fastcgi "Status: 304\r\n".

:

HTTP/1.1 304
Server: nginx/1.6.2
Date: Sat, 21 May 2016 10:49:27 GMT
Connection: keep-alive

, Status: 304. nginx.

+1

Source: https://habr.com/ru/post/1527290/


All Articles