3

I have the following nginx configuration for the url rewrite

location / { ##merge
    try_files $uri $uri/ /index.php?q=$uri&$args;
}

location /devtools/phpmyadmin/ { ##merge
    root /var/www/domain.tld/web;

    location ~ \.php$ {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/lib/php5-fpm/web2.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
    }
}

in the /var/www/domain.tld/web/ directory have an /api/ directory and I want disable for the url rewrite for this. So if I woud like access from url with index.php: http://domain.tld/api/index.php/function/method

How can I modify the nginx config file?


Edit:

I try the following rewrite, but not working:

location = /api {
    rewrite ^ /api/index.php;
} 
Richard Smith
  • 45,711
  • 6
  • 82
  • 81
wpdaniel
  • 714
  • 8
  • 25
  • Is there a `root` directive above the first `location` block? Do you have a `location ~ \.php$` block at the `server` block level? – Richard Smith Jul 23 '16 at 17:04
  • @RichardSmith No root directive above the first location block and the other question is no - I edit the nginx config from ispconfig – wpdaniel Jul 23 '16 at 17:31

1 Answers1

2

I confess that I do not understand your configuration file. Generally, you would define a root to be inherited by all (or most) of your location blocks. And usually a separate location ~ \.php$ block to handle off-loading .php scripts to a PHP processor via FastCGI.

Ignoring your location /devtools/phpmyadmin/ block for the moment, a typical implementation would look like this:

root /var/www/domain.tld/web;

location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
}

location ~ \.php$ {
    try_files $uri =404;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass unix:/var/lib/php5-fpm/web2.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors on;
}

The nginx directives are documented here.

If you want URIs that begin with /api to use a different controller, you could add:

location /api {
    try_files $uri $uri/ /api/index.php;
}

I cannot see the purpose of the location /devtools/phpmyadmin/ block, as it does not seem to add any more functionality.

Richard Smith
  • 45,711
  • 6
  • 82
  • 81