+1
Completed

reverse proxy to example.com/ajenti

Masaki Adachi 6 years ago updated by Eugene Pankov (Project coordinator) 6 years ago 3

Hello there!  I copied the reverse proxy code for nginx from your documentation and was scratching my head why it was not working in my environment.


server {
    server_name fallthrough;
    client_max_body_size 20m;
    listen 80;
    location /ajenti {
        rewrite /ajenti/(.*) /$1 break;
        proxy_pass  http://127.0.0.1:8000;
        proxy_redirect / /ajenti/;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

to make a long story short, it turned out that the way it is written, one has to always add a trailing slash to uri to make it work. (ie., //example.com/ajenti/)   I ended up adding another rewrite directive right before the existing rewrite, so "//example.com/ajenti"  is properly handled.

    	rewrite (/ajenti)$ / break ;
        rewrite /ajenti/(.*) /$1 break;
I think I can smart these up into one liner but my brain is mash now :)

As I suspected, my brain was not working last night.

 rewrite /ajenti/?(.*) /$1 break;

Rewrite! previous one even matches /ajentibrahbrah

        rewrite /ajenti($|/(.*)) /$2 break;