1

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; } } } 
18
  • Have you tried 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. Commented Jan 25, 2021 at 7:31
  • I've tried your solution, same error now looking for /etc/nginx/html/app/api/code/index.php path. Commented Jan 25, 2021 at 7:34
  • Try with text files instead of PHP files. Commented Jan 25, 2021 at 7:37
  • I've tried index.html and is correctly served. Commented Jan 25, 2021 at 7:38
  • The correct URI for index.php is /api/v1/index.php and not /index.php. Both location and alias should end with a / or neither end with a /. Use fastcgi_param SCRIPT_FILENAME $request_filename; when using alias. Commented Jan 25, 2021 at 7:39

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.