regexnginxscgi

Nginx Variable + regex inside config


In my /etc/nginx/nginx.conf

1st example:

location ~ ^/~(.+?)(/.*)?$ {
    alias /home/$1/web$2;
    index  index.html index.htm;
}

It means if I visit httpwebsite/~user1/ it will redirect web folder to /home/user1/web

and If I visit httpwebsite/~nextuser/ it will redirect to /home/nextuser/web

2nd example: Now I want to do the same with scgi mount:

location ~ ^/RPC-user1$ {
    include scgi_params;
    scgi_pass /home/user1/scgi.socket;
}
location ~ ^/RPC-nextuser$ {
    include scgi_params;
    scgi_pass /home/nextuser/scgi.socket;
}

How to translate this 2 lines of code to wildcard 1 line like the 1st example? Basically passing anything like /RPC-$USERNAME to scgi_pass /home/$USERNAME/scgi.socket


Solution

  • Try this:

    location ~ ^/RPC-(.+)$ {
        include scgi_params;
        scgi_pass /home/$1/scgi.socket;
    }