Get arguments Nginx and path for proxy_pass

2019-08-19 19:30发布

问题:

I have this URL:

http://localhost:8888/images/upload/root/folderA/folderB?arg1=A&arg2=B

so, I want redirect all to:

http://localhost:8080/v1/files_upload/

and it must be something like:

http://localhost:8080/v1/files_upload/root/folderA/folderB?arg1=A&arg2=B

I have the following:

location ~ ^/images/upload/([^/]+)(/.*)\?(.*)$ {

     upload_pass @after_upload;
     ...
     ...

}
location @after_upload {
            proxy_pass   http://localhost:8080/v1/files_put/$1/$2?$3;
    }

I checked it, and only works $1 and $2, but the arguments $3 are not sent to proxy_pass

Thanks in advance!

回答1:

The location directive doesn't match request arguments, it only checks request path. You should use the $args variable (or more specific $arg_arg1 and $arg_arg2):

location @after_upload {
    proxy_pass   http://localhost:8080/v1/files_put/$1/$2?$args;
}