I have an nginx config that looks like this:

location ^~ /movies {
    alias /var/dp.cx/movies/current/public;
    fastcgi_index index.php;
    try_files $uri /movies/index.php;

    location ~* \.php {
        fastcgi_pass unix:/run/php/php7.1-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        include /etc/nginx/fastcgi_params;

This is a Laravel application, which works almost completely out of the box. However, there are a couple of small problems that I have with this configuration.

  • Hitting /movies triggers a 404. Hitting /movies/ works successfully.
  • Hitting one of the pagination URLs (/movies/test?page=2) has no information from the querystring.

I'm not sure where I found this configuration, but it seems to be the closest thing to a "working" configuration I've ever found for nginx + fpm with a subdirectory URL.


Hitting /movies triggers a 404. Hitting /movies/ works successfully.

To solve it at the server-level... please add the following location block alongside the existing location block for movies...

location = /movies {
  return 301 $scheme://$host/movies/;

Hitting one of the pagination URLs (/movies/test?page=2) has no information from the querystring.

It is due to try_files line that doesn't pass the query string. To pass it, using the following try_files directive would work...

try_files $uri /movies/index.php$is_args$args;

Direct quote from http://nginx.org/en/docs/http/ngx_http_core_module.html ...

$is_args - “?” if a request line has arguments, or an empty string otherwise.

| improve this answer | |
  • The location = /movies portion worked perfectly. Sadly, adding the $is_args$args triggers every page under /movies to return a 404. – Glen Solsberry Oct 5 '17 at 22:59
  • Do you have a way to check if query string is received by the application? If yes and if the application indeed receives the query string, then the issue is with the application. Also, it is a good practice to upvote an answer that helped you. See serverfault.com/help/someone-answers . Also, asking only one question at a time is a good practice. When two persons give a correct answer to just one question each, how would you choose the right answer? – Pothi Kalimuthu Oct 5 '17 at 23:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.