0

I'm trying to deploy a web application for building REST services. The application is built using PHP and you BYO web server and database software. I'm using Nginx and MySQL (MariaDB). I've managed to deploy it using the following Nginx config:

server {
    listen 80;
    listen [::]:80;

    root /var/www/fusio;
    index index.php index.html index.htm;

    server_name localhost;

    location / { 
       try_files $uri $uri/ =404;
    }

    location ~ ^.+.php {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;

        set $path_info $fastcgi_path_info;
        fastcgi_param PATH_INFO $path_info;

        try_files $fastcgi_script_name =404;

        include         fastcgi_params;
        fastcgi_pass    unix:/run/php/php7.3-fpm.sock;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index   index.php;
    }

}

When I deploy new endpoints in the application, they deploy at http://localhost/local/index.php/my_url. I would like them to deploy at http://localhost/my_url. The developer of the application, who is familiar with Apache, suggested I enable mod_rewrite, which as I understand it is effectively a redirection capability.

I want to know how I can do the same redirection in Nginx without breaking the fastcgi config I have set up. Is it possible, and if so how? The existing rewrites I've tried such as rewrite ^/index.php/(.*) /$1 permanent; and rewrite ^(.*)$ /index.php don't seem to do the trick.

Thanks in advance

damiante
  • 1
  • 2
  • In the `location /` block, you could try using: `try_files $uri $uri/ /local/index.php$uri;` – Richard Smith Mar 30 '20 at 06:35
  • Tried this and it didn't work; I feel like the solution is something like this but I also feel like it might break the fastcgi path splitting if I manage to get it right. – damiante Mar 31 '20 at 00:27
  • Actually, this does appear to work! I think it's because I wrote my path wrong in my question; fixing it for my machine solved the problem. Thanks! – damiante Apr 01 '20 at 00:03

1 Answers1

0

Richard Smith answerwed my question above; replacing the =404; part of the try_files line in my location / directive with (the equivalent of) /local/index.php$uri; allows the php requests to continue as though they have accessed the appropriate index.php but without showing them in the address and without impacting the ability of the application to run its internal scripts. Thanks Richard!

damiante
  • 1
  • 2