Skip to content

Using Magento 2 in subdirectory calling nginx.conf.sample

I looked at this question but I believe magento has changed since then

I am trying to set the location block for calling magento 2.4.6-p3 from a subdirectory with the following
in my nginx 1.24 server configuration:

    location ^~ /subdirectory/ {
        set $MAGE_ROOT /var/www/example.com/subdirectory;
        include /var/www/example.com/subdirectory/nginx.conf.sample;
    }

but when running

nginx -t

I get the following error:

nginx: [emerg] location "/.user.ini" is outside location "/subdirectory/" in /var/www/example.com/subdirectory/nginx.conf.sample:42

which corresponds to this part in the nginx.sample.conf

location /.user.ini {
    deny all;

what additional info would I need in the server configuration file to avoid this error?