Search code examples
regexnginxproxypass

Nginx: location regex not working


i'm getting trouble with my regex don't know what is wrong with it. it's returning a URi with orls/f instead of orls/f?p=4550. When i pass https://secure.toto02.com/orls/myservice/f?p=4550

my conf file is below

 location ~ "^/([a-zA-Z]+)/myservice/(.+)$" {

    error_log  /var/log/nginx/error-server.log notice;
    rewrite_log 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_header        X-Forwarded-Proto $scheme;


    proxy_pass http://192.168.3.45:8080/orls/$2;    
    proxy_redirect http://192.168.3.45:8080/orls/ https://secure.toto02.com/$1/myservice/ ;          
}   

Can anyone help?


Solution

  • Capturing the location will not encompass the query string. You have to manually include it via $is_args and $args variables like so:

    proxy_pass http://192.168.3.45:8080/orls/$2$is_args$args;