NGINX PHP FPM - Download prompt when accessing directories

Francis Daly francis at daoine.org
Sun Aug 30 23:08:21 UTC 2020


On Sun, Aug 30, 2020 at 04:43:27PM +0000, Laura Smith wrote:

Hi there,

> I have a largely working NGINX config as below.  The only problem is that when "/administrator" or "/administrator/" or "administrator/foo.php" is called, I always get prompted to download the PHP file rather than it be executed by PHP FPM.  Meanwhile, calls to "/" or "/foo.php" operate as expected  (i.e. executed correctly by PHP FPM).
> 

In nginx, one request is handled in one location{}.

Your

>       location ^~ /administrator/ {

will handle all requests that start with /administrator/; that location
does not do any special handling of php requests; all it will do is
serve files from the filesystem.

Depending on how you want the requests handled, possibly removing the
"^~" will work (that would mean that any requests that match other
regex-location{}s will not be handled in this location); or possibly
creating a nested regex location for "~php" within this location will
work (with contents very like the "main" php location).


(Your config seems to want basic authentication for "file" requests,
but not for "php" requests; that may well be what you intend.) (And the
limit_except lines seem redundant with the "if ($request_method" line;
but if what you have works, it works.)

Good luck with it,

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list