0

I want to parse the key information area code based on the post message, and then forward it to a specific address based on the region code. May I ask if my settings below can be forwarded to an address, but why is the forwarded body content empty? How can I fix it? Do I have to use OpenResty?

server {
listen 8850;

location / {
    proxy_pass_request_body on;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_body "$request_body";
    proxy_set_header Content-Type "application/xml";
     
    if ($request_body ~* "<areaCode>(123|245|789)</areaCode>") {
        set $backend backend1;
    }
    if ($request_body !~* "<areaCode>(123|245|789)</areaCode>") {
        set $backend backend2;
    }
    
    proxy_pass http://$backend;
}
}
flower
  • 2,212
  • 3
  • 29
  • 44
  • `proxy_pass_request_body on` should be the default. Why are you using `proxy_set_body`? My recommendation anyways would be to use Lua for this. Also a few related questions:https://stackoverflow.com/questions/22788236/how-can-i-manipulate-the-json-body-of-a-post-request-using-nginx-and-lua https://stackoverflow.com/questions/49584910/modify-request-body-before-proxy-pass – Ricardo Alves Jul 21 '23 at 09:38

0 Answers0