I'm trying to make a small server to study using fastCGI with C ++ without using any library. My problem is that via socket NGINX even connects but does not give me any information about the request, and if I write some callback it generates error 502.
NOTE: I am using a class Socket I created. link
Here's my C ++ code.
#include "Socket.h"
#include "thread"
using namespace Tigre;
int main(int argc, char *argv[], char** envp) {
try {
Socket *s = new Socket("localhost", 9000, TCP);
s->Bind(5);
std::cout << "Esperando Cliente\n";
Socket *cliente = s->Accept();
//cliente->Write("\r\n");
//cliente->Write("Bem vindo ao servidor!");
std::cout << "Esperando Mensagem do Cliente\n";
int i = 0;
while(i < 100) {
std::cout << "'"<< cliente->Read() << "'" << "\n";
i++;
}
}catch (SocketException &e){
std:cerr << e.what();
}
}
NGINX Configuration:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root share/nginx/html;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_pass 127.0.0.1:9000;
}
}
}
EDIT1: I made a change in the std::cout << "'"<< cliente->Read() << "'" << "\n";
line to check if there was any blank value, and it actually arrives as you can see below.
OBS2 The error only occurs when Nginx generates error 502 and returns to the browser.
Console:
Esperando Cliente
Esperando Mensagem do Cliente
''
'Sem conexão com o Socket.
Process finished with exit code 0