nginxuser100
nginxuser100

Reputation: 41

How to pass custom parameters between FCGI servers in C via NGINX?

Intro

My FastCGI servers are written in C. I would like the FCGI auth server to pass some custom parameters (such as some parameters returned by a Radius server) to a FCGI "back-end" server.

My Question

Does NGINX support passing custom parameters between two FCGI servers in C? If yes, I would appreciate some help on the following:

  1. how to program the FCGI auth server to pass the variable to NGINX.
  2. how to program the FCGI back-end server to read the custom parameters
  3. how to configure the nginx.conf file. In my example below, I have "fastcgi_param CUSTOM_PARAM custom_param;". I don't know whether that is the way to do it, I went by how it is done with a HTTP header parameter.

curent work

This is what I have. The FCGI /auth server would set the custom_param variable, and I would like NGINX to forward this variable to the FCGI back-end server.

location / {
    auth_request /auth;
    include fastcgi_params;
    fastcgi_pass   127.0.0.1:9000;
}

location = /auth {
    include fastcgi_params;
    fastcgi_param CUSTOM_PARAM custom_param;
    fastcgi_pass   127.0.0.1:9010;
}

Thanks for your help!

Upvotes: 4

Views: 3379

Answers (1)

Ben Grimm
Ben Grimm

Reputation: 4371

Authentication handlers pass information back to the server via http headers. With nginx you'll use auth_request_set to assign those values to variables:

location / {
    auth_request /auth;
    auth_request_set $receive_from_auth $upstream_http_x_custom_param;
    include fastcgi_params;
    fastcgi_pass   127.0.0.1:9000;
}

Sending parameters to FCGI from nginx works the way you indicated:

location = /auth {
    include fastcgi_params;
    set $send_to_auth yourvalue; 
    fastcgi_param CUSTOM_PARAM $send_to_auth;
    fastcgi_pass   127.0.0.1:9010;
}

And those parameters are read from the environment:

char *custom_param;
custom_param = getenv("CUSTOM_PARAM");

Upvotes: 2

Related Questions