0

I'm receiving post request from client server where it comes in with some post data and then be saved to database after being passed to my server which is running nginx, I don't know exactly how to configure Nginx to receive those request and foward them to application backend using specific url where I will be able to save them in database. I would like nginx to give the client ip address and the posted request.

Thank you, Im still learning how to use Nginx properly.

Here is what i have tried to do but no success

server{
  listen 80;
    server_name my_server_ip;
    error_log /var/log/nginx/error.log;
    # proxy_pass_header Server;

   location / {

           proxy_pass http://127.0.0.1:8000;
           proxy_set_header X-Forwarded-Host  $server_name;
           proxy_set_header X-Real-IP         $remote_addr;

         }

       location /user/user_request/{
           if ($request_method != 'POST'){
             return 405;
          }

          return 200;
          proxy_set_header X-Forwarded-For $remote_addr;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          keepalive_requests 10;
          keepalive_timeout 75s;
          proxy_pass http://my_server_ip$request_uri;
    }


}
pedros
  • 46
  • 2
  • 9

1 Answers1

2

Remove the return 200; line as this is returning the function and the lines below it are not being executed. You don't need to return 200 from this part, as that will be handled by the application that you're forwarding the request over too.

tdsymonds
  • 1,679
  • 1
  • 16
  • 26
  • The post request from client server will not be posted to my server if it does not respond with a header of 200 OK. Thats why return 200 first – pedros Dec 15 '17 at 12:57
  • Tried that, the client server reply 502 bad gateway – pedros Dec 15 '17 at 13:14
  • I have removed `return 200` and I have modified `proxy_pass` to `proxy_pass http://my_server_ip/user/user_request/`, and now nginx error log saying worker_connections are not enough fail while reading response header from upstream. – pedros Dec 15 '17 at 13:56