With some (or very much) trial and error i was able to modify my copy and pasted nginx fastcgi php configuration from somewhere years ago to be able to run my php application in a subfolder.
But the last final step i am not able to solve is how to get nginx to pass the query string to php to be able to access the GET parameters. This is my configuration mostly perfect with only the configuration parameters missing:
server {
listen 80;
server_name project.dev;
location /app/ {
alias /path/to/my/application/;
index index.php;
try_files $uri $uri/ /app/index.php;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
}
}
location / {
# configuration for static website
}
}
I read that there are different options you have to pass to try_files to get request parameters:
try_files $uri $uri/ /app/index.php$is_args$query_string;try_files $uri $uri/ /app/index.php$is_args$args;try_files $uri $uri/ /app/index.php?$query_string;
Unfortunately changing it to any of these results in my php script no longer being found because nginx resets the request to it's document root:
2016/11/25 11:54:48 [error] 45809#0: *1169 open() "/usr/local/Cellar/nginx-full/1.10.2/htmlindex.php" failed (2: No such file or directory), client: 127.0.0.1, server: project.dev, request: "GET /app/myurl?test=works HTTP/2.0", host: "project.dev", referrer: "http://project.dev/app/myurl?test=works"
Providing an absolute path for fastcgi_param SCRIPT_FILENAME does not work too producting the same error. Even setting a root configuration on the server level does not work correctly, because the separating slash for the path and the index.php is omitted everytime. But (if possible) i would prefer without setting a root directory at the server level because this project is consisting of many different folders and applications on the filesystem sharing no common directory.
/path/to/my/application/?/path/to/my/application/with all its assets and it's php. Loading of the assets and running the php works exactly as expected, but for some reason i can't pass the $_GET parameters to the fastcgialiasandtry_files. You want to run your application under the URI/app, things would be very simple if/path/to/my/application/ended with/app(the same subdirectory name as the URI)./is another website with it's own filesystem and structure i am not allowed to mess with. Buttry_fileswithaliasis working perfectly: PHP gets called, assets are sent - only the request parameters are not sent to PHP. It only goes downhill as soon as i add these suffixes to get the query string.PHPfile under/path/to/my/application/? BTW all you need to do is make a directory calledappwhere your files are and move them into it - I'm not asking you to change anything in/.