21

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
geekscrap
  • 965
  • 2
  • 12
  • 26

1 Answers1

36

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/"
Patrick Lee
  • 1,990
  • 1
  • 19
  • 24
  • 2
    Use a modern text editor and change all the lines at the same time with multiple cursors – isapir Apr 27 '17 at 23:04
  • 8
    I'm confused a little... If inner URLs are not relative to the outer URLs then what is the purpose of nesting locations...? – Iorweth333 Sep 30 '21 at 09:23
  • 5
    Do the inner `location` blocks inherit the other properties from the outer blocks, e.g. `proxy_read_timeout` or `proxy_pass`? – fiedl Feb 10 '22 at 11:01
  • @fiedl it does not, see here: https://forum.nginx.org/read.php?2,174517,174534#msg-174534 or try it here: https://nginx.viraptor.info/ – tonnoz Jan 27 '23 at 15:30