Rewrite Laravel URL when not in root path with NGINX

In the most cases, we place the Laravel in the root path /.

As a result, the nginx configuration becomes

However, if we want to move Laravel inside other directories, we must also change the location directive along with the public/index.php file.

Let’s say we want to move to the /app directory. Then the location directive would become

Since nginx indicates the root path already, so we have to always refer from the root path.