I'm not getting through this.
My server is app.local and I need to respond to:
http://app.local/api/v1/ I need to configure my nginx to serve files placed in:
/app/api/code So the filesystem is not reflecting the http request form.
CURRENT VERSION
server { server_name app.local; index index.php; location /api/v1 { alias /app/api/v1/code; try_files $uri /api/v1/index.php$is_args$args; location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass api-v1-php:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $request_filename; } } } Ok, if I remove the outer try_files it seems to find the index.php, BUT i lose some functionality (I need to redirect every path to the index handler). How can I solve this? Is this a bug?
SOLUTION
This post had the solution: https://stackoverflow.com/a/35102259/2373113
UPDATED VERSION
server { server_name app.local; index index.php; location /api/v1/ { alias /app/api/v1/code/; try_files $uri $uri/ /api/v1//api/v1/index.php$is_args$args; location ~ /api/v1/.+\.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass api-v1-php:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $request_filename; } } }
try_files $uri /app/api/code/index.php$is_args$args;? You should first try to solve the issue for non-PHP files, and only then move on to the PHP case.index.phpis/api/v1/index.phpand not/index.php. Bothlocationandaliasshould end with a/or neither end with a/. Usefastcgi_param SCRIPT_FILENAME $request_filename;when usingalias.