3

I've a nginx conf in Direct Admin with a custom location:

Code:

location /reset-password {
     alias /home/**/domains/**.**/public_html/api/frontend-scripts/resetPassword;
     include /usr/local/directadmin/data/users/**/nginx_php.conf;
}

This isn't working; nginx shows 'File not found.' for all PHP related files in the browser. Plain HTML is working fine.

I've tried several other solutions, i.e.:

Code:

location /reset-password {
    alias /home/**/domains/**.**/public_html/api/frontend-scripts/resetPassword;
    # use fastcgi for all php files
    location ~ \.php$
    {
       try_files $uri index.php;
       fastcgi_split_path_info ^(.+\.php)(/.+)$;
       include /etc/nginx/fastcgi_params;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include /etc/nginx/nginx_limits.conf;
       if (-f $request_filename)
       {
           fastcgi_pass unix:/usr/local/php56/sockets/**.sock;
       }
    }
 }

All of them are giving a 'File not found.' in the browser.

So it probably has something to do with phpfpm, but I'm out of options. What am i doing wrong?

Roy Milder
  • 886
  • 2
  • 11
  • 19

1 Answers1

2

Using alias with PHP is always problematic as the $document_root$fastcgi_script_name statement is no longer valid.

You could use:

fastcgi_param SCRIPT_FILENAME $request_filename;

But an open bug in nginx makes the use of try_files with alias a little unpredictable.

My preferred solution is to invisibly rewrite the URI so that a root directive can be used:

location ^~ /reset-password {
    rewrite ^/reset-password(.*)$ /resetPassword$1 last;
}
location ^~ /resetPassword {
    root /home/**/domains/**.**/public_html/api/frontend-scripts;
    ...
}

Also notice that the ^~ modifier causes these prefix location blocks to take precedence over other regular expression location blocks at the same level (e.g. another location ~ \.php$ block) should there be one.

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