Hello everyone, I wrote a rule for nginx, does not work, gives an error

/var/www/api/api_users/index.php/main/get" failed (20: Not a directory) 

My config

 server { server_name api.auto.as; root /var/www/api/; index index.html index.php; location / { rewrite ^/(.*)\.(.*)$ /api_$1/index.php/main/$2?$query_string break; } location ~* \.php$ { fastcgi_pass unix:/run/php/php7.2-fpm.sock; include fastcgi.conf; } } 

Request: http://api.auto.as/users.get

Tell me the solution.

  • one
    Obviously, /api_user/index.php/main/get does not fall into ~* \.php$ - nörbörnën
  • how then to write correctly? - Vadym

1 answer 1

A simple solution

 location ~* \.php { fastcgi_pass unix:/run/php/php7.2-fpm.sock; include fastcgi.conf; } 

Correct solution

 location ~ ^/([a-zA-Z]+).([a-zA-Z]+)$ { include fastcgi.conf; fastcgi_pass unix:/run/php/php7.2-fpm.sock; fastcgi_param SCRIPT_FILENAME /api_$1/index.php/main/$2$is_args$args; # может fastcgi_param QUERY_STRING $query_string; # может fastcgi_param REQUEST_URI /api_$1/index.php/main/$2$is_args$args; } 

The correct solution does not allow ambiguities and is easy to live with, the only difficulty is that I don’t know which of the parameters passed to the backend (fastcgi_param) needs to be changed. Need to smoke dock , wiki .