skip to Main Content

How to match all files with or without extension, except those with the extension txt, pdf, jpeg.

On my Nginx configuration this downloads all the files without any restriction.

location ~ .+(?<!.pdf|.txt|.jpeg)$ {
        
    auth_request /auth.php;
    error_page 401 = @login;
} 

Thanks

2

Answers


  1. Chosen as BEST ANSWER

    Solved I auth.php was not included as an exception which would cause a loop.

    location ~ .+(?<!/|auth.php|.txt|.pdf|.jpeg|.jpg|.png)$ { 
    
        auth_request /auth.php;
        error_page 401 = @login;
    
    }
    

  2. What about defining two locations? E.g.

    location ~ .(pdf|txt|jpeg)$ {
        # handle those with the extension pdf, txt, jpeg
    }
    location / {
        # handle all files with or without extension
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search