Search code examples
nginxproxypass

Nginx dynamic proxy_pass


I'm trying to configure nginx to proxy when $1 is the path to a unix socket and $2 the uri :

  • /user/<username> => /tmp/<username>/socket.sock /
  • /user/<username>/a => /tmp/<username>/socket.sock /a
  • /user/<username>/a/b => /tmp/<username>/socket.sock /a/b

location ~/user/(.+)/(.*)$ { proxy_pass http://unix:/tmp/$1/socket.sock:/$2
}

Of course it doesn't work for the third example


Solution

  • I finally found :

    location ~/user/(\d+)/(.*)$ {
        proxy_pass http://unix:/tmp/$1/socket.sock:/$2
    }