proxy_pass listen port forward data to url as POST request

Viewed 14

I'm using nginx to listen to a port, what I want to do is forward whatever data is sent to that port to an API endpoint I made, using the full route.

Let's say I'm listening to port 3000 and I receive the following string: "XXXX,AAAA,1234,0.9898,FFFF"

What I want to do is send that same string in a POST request to my API endpoint POST http://localhost:5000/api/something/something-else

Here's my nginx.conf file:

http {
    server {
        error_log /var/log/nginx/error.log info;
        listen 3000;
        location / {
            proxy_set_header Connection $http_connection;
            proxy_pass http://localhost:5000/;
            proxy_redirect http://localhost:5000/ http://localhost:5000/api/something/something-else;
        }
    }
}

All I get is the following error:

client sent invalid method while reading client request line, client: 172.19.0.1, server: , request: "XXXX,AAAA,1234,0.9898,FFFF"

And this line with a 400 bad request status code:

172.19.0.1 - - [16/Sep/2022:01:08:43 +0000] "XXXX,AAAA,1234,0.9898,FFFF" 400 157 "-" "-"

I understand that proxy_redirect may not be the directive I need here. This is my first time doing this and I'm kinda lost, any help is appreciated.

0 Answers
Related