0

My root structure looks like this

/root/ /root/projectA/... /root/projectB/... /root/projectC/...

Before I configured each of my subdirectories with one extra location block in my nginx file. These location "blocks" looked like this:

server { listen 80; listen [::]:80; root /usr/share/root/projectA/public/; index index.php index.html index.cgi; server_name www.test.de; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_index index.php; include fastcgi_params; } 

}

This way my ZF2 application residing in /root/projectA worked as expected. But as the number of subprojects grow, I wanted to use an generic regex solution so I don't have to write the same block over and over again for each subdirectory.

So this was my approach to make those projects available under a subdomain vendor.test.de with each project available under vendor.test.de/projectA/...:

server { listen 80; listen [::]:80; root /usr/share/root/; index index.php index.html index.cgi; server_name vendor.test.de; rewrite_log on; error_log /var/log/nginx/debug.log debug; location ~ ^/(.+)/ { root /usr/share/root/$1/public; try_files $uri $uri/ $1/public/index.php?$args; location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_index index.php; include fastcgi_params; } } 

}

But all I get is a 404 and it's just not working. I debugged the log files a bit, and it seems to behave strange with trying to get /usr/share/root/index.php instead of /usr/share/root/projectA/public/index.php even though he found the right location first...

Any ideas on this?!

Thanks in advance!

1
  • Thanks @Evils, the question itself helped me configure nginx to use index.php as default in subdirectories! Commented Jun 24, 2014 at 2:33

1 Answer 1

3

In your location you need to use alias instead of root.

 alias /usr/share/root/$1/public/; 
2
  • That doesn't work for me. I still get path errors as nginx is searching on /usr/share/rootprojectA and missing the slash in between. Commented Mar 2, 2014 at 12:26
  • You're also missing a / in your try_files, i.e. /$1/public/index.php Commented Mar 2, 2014 at 16:00

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.