php - Nginx root inside location not working


I am using nginx 1.8 and knowing about the alias/try_files bug i wrote the following nginx conf:

root /var/www/
location  /foo/ {
   root /var/www/projects/bar/public/;
    try_files $uri $uri/ index.php;


in which i get a 404, but if i write the following way (which should point to the same location)

  root /var/www/
  location   ~ ^/foo/(.*)$  {
    try_files /projects/bar/public/$uri /projects/bar/public/$uri/ /projects/bar/public/index.php;


i get the contents. Why the other root seems not to be applyied?

People are also looking for solutions to the problem: php - How to get a callback for every echo?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.