Regex – how to excluded directory from nginx conf


in nginx conf file,i use:

location ~ \.jsp {

to parse my jsp file, now,i want excluded directory /upload/

this directory is user upload file directory ,don't need parse JSP file.(

how to change my location ~ \.jsp { ?

i need parse JSP *.jsp but excluded /upload/ and it's subdirectory.

thanks all 🙂

Best Solution

Here is a list of Nginx Core Directives:

By skimming through these I can see there's probably more than one way to achieve this. I can't test it, but here's something that may work:

error_page 403 /forbidden.html;
location ^~ /upload/ {
    deny all;

However, I would advise against this; your upload directory should never sit inside your web root. You should simply move the folder to achieve what you're asking.