Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested locations in nginx

Hi I'm trying to get the following to work!

I'm basically trying to allow the following URLs to be passed to the proxy_pass directive by either of these two URLS:

http://example.com/admin/1 or http://example.com/admin/2/

I have the following config:

location /admin/ {

        # Access shellinabox via proxy
        location 1/ {
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_pass http://example.com;
        }

}

At the moment, an error is thrown:

2016/01/17 15:02:19 [emerg] 1#1: location "1/" is outside location "/admin/" in /etc/nginx/conf.d/XXX.conf:37
nginx: [emerg] location "1/" is outside location "/admin/" in /etc/nginx/conf.d/XXX.conf:37
like image 333
geekscrap Avatar asked Jan 17 '16 15:01

geekscrap


1 Answers

You should use /admin/1/ in your inner location block as the inner URLs are not relative to the outer URLs. You can see that this is the issue based on the following snippet from the error message you included...

location "1/" is outside location "/admin/"
like image 104
Patrick Lee Avatar answered Sep 19 '22 14:09

Patrick Lee