In general, your example is parsed in the documentation for nginx :
Processing the “/” request is more complex. Only the prefix location “/” corresponds to it, therefore the request is processed in it. Then the index directive checks the existence of index files according to its parameters.
In addition, I highly recommend repeatedly, until full enlightenment, to re-read the section "procedure for applying location" (for example, one and two times ).
Specifically, your example is parsed to the smallest detail.
How to understand URI / in your config:
A) for the case of an empty location / :
- For the request
/ only one location is suitable - location / . This location is empty, but inherits root and index from the server block. - Internal redirection (index directive) is applied from
/ to /index.php . Processing of the new request begins. - For the
/index.php request, both location ~* \.php$ and location \ are suitable, will be used (see location priority order) location given by the regular schedule, it will give 403 and finish processing the request.
For clarity, the equivalent server configuration:
server { listen 80; server_name example.com; root /home/Web/www/$server_name/; charset utf-8; location ~* \.php$ { return 403; } location / { index index.php index.html; } }
So clearly shows that your example is fully consistent with the disassembled documentation.
B) for the case of a location with a proxy server
- For the request
/ only one location is suitable - location / . This location transfers the backend processing, at that the request processing by nginx is completed.
This is what concerns the query given in the question itself. There was another request in the comments:
If you type example.com/index.php, then location ~ * .php $ {} works, regardless of whether there is something in the location / {} block or not.
For the request /index.php , which location is suitable? That's right - both, but the first will be applied to the location ~ * .php $ (see the priority of the location), and in it your processing ends with issuing 403.
How to fix it?
Above, I described how your config works. From your point of view, it works "wrong". But how correctly - you do not write, so here you need to clearly set the task - what do you actually want from nginx? I completely agree with the comment. Что «и подобное»? - this is vague and incomprehensible.
I suspect you need location = / {...} but not sure. It may be worth asking a new question, in which to refer to the current and clearly explain what you want to see the location and what you want to send. And it is better not to try "for example" to replace one action with another: if you want to give the file - write like this, and not "give the file, but instead for the example 403". It only confuses you as a questioner and respondents.
index.phpif you still proxy the request? - Alexey Tenlocation ~* \.php$ {}, when going to example / test.html and the like, it proxied the request.return 403;just given as an example. - Vadimexample.com/about/where should it lead? - Alexey Tenlocation ~* /.$ { proxy ... }although I cannot vouch for accuracy, does$accept whether it is appropriate~*... - Mike