skip to Main Content

Today, I have a problem with NGINX.

In my NGINX config I have this :

location ~ / {
    try_files $uri $uri/ /index.php?$query_string;
}

For example, I want to access https://my.domain/hello with a route defined with Laravel. It works
but now if I access https://my.domain/hello/ it returns a 404 NGINX error page. I also point out that I use Plesk.

Do you have any ideas on how to fix that ?

Thank you for your time 😉

2

Answers


  1. Add 301 redirect if path is not directory and ending on /

    if (!-d $request_filename) {
       rewrite ^/(.*)/$ /$1 permanent;
    }
    
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    
    Login or Signup to reply.
  2. If you check the nginx config template you will find this line

    /usr/local/psa/admin/conf/templates/default/domain/nginxDomainVirtualHost.php

            <?php if ($VAR->domain->physicalHosting->directoryIndex && !$VAR->domain->physicalHosting->proxySettings['nginxProxyMode']): ?>
         location ~ /$ {
             index <?=$VAR->quote($VAR->domain->physicalHosting->directoryIndex)?>;
         }
             <?php endif ?>
    

    You either need to reenable proxy mode (it will reenable apache but nginx will still be receiving the request in the first place) or create a custom template for your domain and delete this line

    This will not concern you, but if you were not using php (eg: nodejs), you could also disable php support, which would also get rid of this line

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search