1

I have this location block within my website.conf:

 location ~ ^/([^/?&:'"]+)$ {
        try_files $uri @root_path;
    }

This part of the file hinders the execution of php files, it always serves them as download.

  • How can I exclude *.php files from this regex expression?
  • What does that regex even mean?
  • Is it even good style to just exclude *.php files in this case?

If somebody could elaborate I would be very grateful.

Some more context: I'm trying out jitsi-meet and I would like to add some php-based functionality to the website.

2
  • 1
    The regular expression location blocks are evaluated in order. You need to make sure that the location ~ \.php$ block (or similar) is placed above this new block. Commented Mar 21, 2020 at 15:23
  • that did the trick - thank you. Do you want to add this as possible answer (even without explicitly answering my questions)? Commented Mar 21, 2020 at 15:46

1 Answer 1

1

The regular expression ^/([^/?&:'"]+)$ matches anything that begins with a / and contains any character except /, ?, &, :, ' and ".

The first character is significant as it means it will only match URIs that contain a single path element (e.g. /foo and /index.php) but will not match URIs that contain another / (e.g. /foo/, /foo/bar and /foo/index.php).

The other characters are probably a mistake as ? and & is unlikely to be encountered by a location statement as Nginx uses a normalised URI which has had the query string removed.


You do not need to exclude .php from this regular expression.

The URIs ending with .php are usually processed by another regular expression location block (e.g. location ~ \.php$).

Regular expression location blocks are evaluated in order until a match is found, so you need to make sure that the location ~ \.php$ block is placed above the regular expression location block in your question.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.