How to set location with extension in NGINX server

10,617

If you want to use regex, use ~ (for case-sensitive matching) or ~* (for case-insensitive matching). Your location block should look like this:

location ~ "phpmyadmin \.(gif|jpg|png)$" {
    root /usr/share/phpmyadmin;
}

You can read more here: http://nginx.org/en/docs/http/ngx_http_core_module.html#location

Share:
10,617
Peter Bielak
Author by

Peter Bielak

I defend freedom and privacy in a digital world using cryptography.

Updated on July 25, 2022

Comments

  • Peter Bielak
    Peter Bielak almost 2 years

    I'm new with NGINX server and I was wondering how to set something like this.

    location phpmyadmin \.(gif|jpg|png)$ {
        root /usr/share/phpmyadmin;
    }
    

    example above fails at server restart.

    Thanks for all answers.

    UPDATE:

    location ~* .(gif|jpg|jpeg|png|ico|wmv|3gp|avi|mpg|mpeg|mp4|flv|mp3|mid|js|css|html|htm|wml)$ {
        root /home/safeftp/www/public_html;
    }
    
    location ~ "phpmyadmin \.(gif|jpg|png)$" {
        root /usr/share/phpmyadmin;
    }