NGINX Upstream server forwarding - nginx

I want to know one thing that is it possible for the NGINX to return the response of one upstream server to another upstream.
I need this as when a request is received I want to get it validated from one upstream server, and if validated then only let the NGINX forward that request to the second upstream server which hosts the main processing engine. And once processed by the second server, it replies back with HTTP response.

Related

what's mean "the request cannot be passed to the next server if nginx already started sending the request body"

http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_request_buffering
i can not understanding "When buffering is disabled, the request body is sent to the proxied server immediately as it is received. In this case, the request cannot be passed to the next server if nginx already started sending the request body."
what's mean "the request cannot be passed to the next server if nginx already started sending the request body"
If you have a service with multiple upstream servers, possibly for load balancing or resilience, and one of the upstream servers fail while Nginx is sending the request body to it, Nginx may try to use another server.
But it can only try another server if it has a complete copy of the original request body (i.e. request buffering enabled) or the client has not started sending the request body yet.

NGINX API Gateway- Does NGINX forwards the to upstream servers

I have a question that in a environment where NGINX is acting as a reverse proxy, then does NGINX forwards or creates a new HTTP request for the upstream server ?
And in case NGINX is configured to perform authentication also, then once the user is authenticated, then in future requests, how NGINX and upstream servers will know that the user is authenticated ?
NGINX forwards the request to upstream servers. It modifies two request headers and removes the empty request headers. When the request is forwarded the requested URL is placed in X-Target header. Refer to NGINX-Blog in NGINX.com.

NGNIX reverse proxy settings

i've successfully managed to set up a reverse proxy which receives data via POST requests from clients and forwards them to a NodeJS server for further processing and storing.
now i would like the nginx reverse proxy to return a 200 OK blank response for all of these requests BEFORE forwarding to the nodeJS server. so the clients will receive the response immediately without the need to wait for the backend server to finish the processing.
if i use "return 202;" inside the location directive, the nginx reverse proxy does respond immediately, but never forwards the request to the NodeJS server.
can this be achieved with nginx?
any help would be much appreciated.
Thanks,

Does nginx upstream server compress response data before it sends back to midstream server?

Here is my situation, browsers send http requests to my reverse proxy nginx server, my reverse proxy nginx server then ask upstream server for response, I was wondering whether upstream server will check if request header has "Accept-Encoding:gzip" and compress response data or just send raw data back to my reverse proxy nginx server?
Because when I use tcpdump to capture http response from upstream server to my nginx server,
I could see so much raw data there.

Is it possible to forward NON-http connecting request to some other port in nginx?

I have nginx running on my server, listening port 80 and 433. I know nginx has a number ways of port forwarding that allows me to forward request like: http://myserver:80/subdir1 to some address like: http://myserver:8888.
My question is it possible to configure nginx so that i can forward NON-http request (just those plain TCP connection) to some other port? It's very easy to test if it's a http request because the first bytes will be either "GET" or "POST". Here's the example.
The client connected to nginx .
The client send:
a. HTTP get request: "GET / HTTP 1.1": some rule for HTTP
b. Any bytes that can't be recognized as HTTP header: forward it to some other port, say, 888, 999, etc.
Is it technically possible? Or would you suggest a way to do this?
It is possible since nginx 1.9.0:
http://nginx.org/en/docs/stream/ngx_stream_core_module.html
Something along these lines (this goes on top level of nginx.conf):
stream {
upstream backend {
server backend1.example.com:12345;
}
server {
listen 12345;
proxy_pass backend;
}
}
This is technically possible for sure.
You can modify open source tcp proxies like nginx module called nginx_tcp_proxy_module or HAproxy.
Or you can write a nginx module similar to above one to do this for you.
if nginx remote proxying with HTTP, your client could use the HTTP CONNECT command, then it connects with the remote port and forwards all data as "raw" (or at least I think so).

Resources