5

Why i can't use variable $user in proxy_pass - like in example below?

server {
    listen 80;
    server_name ~^(?P<user>[a-z|A-Z|0-9|_|-]+)\.example\.net$;
    root /home/$user/webapps/;

    location /app/ {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://unix:/home/$user/webapps/app/run/gunicorn.sock:/;
    }
}

Is this possible to achieve or should i give up?

And this one would be perfect, but it is also not working.

server {
    listen 80;
    server_name ~^(?P<user>[a-z|A-Z|0-9|_|-]+)\.example\.net$;
    root /home/$user/webapps/;

    location ~ ^\/(?P<app>[\w-_]+)(\/.*)?$ {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://unix:/home/$user/webapps/$app/run/gunicorn.sock:/;
    }
}

I read this and that and here but none of them cover proxy_pass through unix socket.

Abc Xyz
  • 638

2 Answers2

1

The proxy pass directives don't see $user and $app as parameter in your case you have to tell him via the $is_args and $args variables like so:

proxy_pass http://unix:/home/$user$is_args$args/webapps/$app$is_args$args/run/gunicorn.sock:/;
skip87
  • 195
  • 2
  • 9
1

Found that 'uri' was the problem not variables, so the correct config should be

proxy_pass http://unix:/home/$user/webapps/$app/run/gunicorn.sock:$request_uri;

i should turn on debugging faster, thank you for support.

I can't check this solution anymore, this is my guess right now - because i went with one conf per app, i will try to unify my config later.

Abc Xyz
  • 638