V
V
Victor2015-04-27 21:04:24
PHP
Victor, 2015-04-27 21:04:24

Why doesn't nginx process the request after finding the index file?

Hello.
There is such a config (nginx + Apache):

location / {
    index index.php;
                proxy_pass http://ip:8080;
    location ~* "^/content/.*\.php$" {
               return 404;
              }
}

In it, all php files from the content folder should not work.
When /content/index.php is requested, everything works as it should.
But when /content/ nginx finds (should, at least) the index file and, in theory, should go through the location set with it again, but this does not happen, the request goes to the proxy and the file is processed.
Why is this happening and how can I make index.php not work when /content/ is requested?
The question is more for understanding than for practical purposes.
From the documentation for index: Please note that when using an index file, an internal redirect is made and the request may be processed in another location.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Victor, 2015-05-14
@v_decadence

The answer is something like this: the index directive works only if nginx is going to give the file from the disk and a folder is found in the current path.
If the current location has a proxy_pass / fastcgi_pass, then nginx doesn't even look for the index file. Accordingly, the second time it does not pass according to the rules and gives control to proxy_pass / fastcgi_pass.
Thanks to Alexey Ten for the answer in the comments to the question.

V
Vlad Zhivotnev, 2015-04-27
@inkvizitor68sl

> Why this happens
Because the request is made to /content/ , not to /content/index.php.
This means that the request processing remains in location /, and does not go below (and in / you have everything in order to give index.php).
> how to make index.php not fire when /content/ is requested
Describe what should happen in location /content/ (and by the way, it doesn't make much sense to nest it in that case).
If you have to work out the auto-index - just write. If another index page should open, just write it.
If there should be an auto-index + a ban on php, then write it like that.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question