Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I come to you today with a super strange comportment on my NGINX reverse proxy.

I use it to be the reverse proxy of a tomcat server and set the host configuration like that:

server {
        listen  80;
        server_name hostname.domaine.tld;

        access_log /var/log/nginx/hostname.access.log;
        error_log /var/log/nginx/hostname.errors.log;

        include errors.conf;
        include proxy.conf;

        location = / {
            deny all;
        }

        location = /manager/(?<uri>\w+)$ {
            deny all;
        }

        location ~ ^/(?<uri>\w+)$ {
            proxy_pass http://recette/$uri;
        }
}

Long story short, I aim to allow access to ressources on this host like that:

host.domaine.tld/ressourcename/(.*)

But I also want to deny any access on the following URLs:

host.domaine.tld/

host.domaine.tld/manager/

host.domaine.tld/manager/(.*)

Here my configuration seems to doesn't work, from what I understand, it's because the third location is always true, even if you set the second location on the configuration file, in this case, you'll always be granted to access the manager vhost even if it's specifically deny.

So, I would like to ask you a little help on this topic because I think that my regex is not correct.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Ok, finally got it!

I messed up my regex :'(

Here is the final configuration file which is perfectly working as intended :D

server {
    listen  80;
    server_name hostname.domaine.tld;

    access_log /var/log/nginx/hostname.access.log;
    error_log /var/log/nginx/hostname.error.log;

    include errors.conf;
    include proxy.conf;

    location ~ ^/$ {
        deny all;
    }

    location ~ ^/manager/(?<$uri>)$ {
        deny all;
    }

    location ~^/(?<$uri>)$ {
        proxy_pass http://recette/$uri;
    }
}

Indeed there were two issues, the first one is the "=" sign which need a perfect match. The second is the added (w+) which conflict with the already exising catch all regex provided by the (?) directive.

So, thanks to the viewer, and sorry for the disturb ^^

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.