cancel
Showing results for 
Search instead for 
Did you mean: 

nginx config not allowing script in subdirectoy of $MAGE_ROOT/pub

SOLVED

nginx config not allowing script in subdirectoy of $MAGE_ROOT/pub

Hi there,

I am using magento 2.4.3 on Rocky Linux with PHP 7.4.19 and nginx 1.14.1

 

I'm using a third party script to enable me to migrate data from magento on one server to another.  However their docs and .htaccess provided are only for Apache.

 

The script must be accessible via https://mymagentodomain.com/le_connector/connector.php

 

The script has a connector which I've installed to:

$MAGE_ROOT/pub/le_connector/connector

 

I added this to nginx.conf.sample:

 

# PHP entry point for main application
location ~ ^/(index|info|le_connector/connector|get|static|errors/report|errors/404|errors/503|health_check)\.php$ {

 

Note I also added info - that works - an info.php file in $MAGE_ROOT/pub is accessible via a browser (at https://mymagentodomain/info.php)

 

However when I try to access https://mydomain/le_connector/connector.php I get a 403 - Access denied. 

 

Can anyone help me with the correct nginx config to allow access to this script - given that the nginx.conf.sample is otherwise as per the standard 2.4.3 Magento distribution - please?

1 ACCEPTED SOLUTION

Accepted Solutions

Re: nginx config not allowing script in subdirectoy of $MAGE_ROOT/pub

So it turned out to be an selinux issue.  This addition to the nginx config was correct:

# PHP entry point for le_connector application
location /le_connector {
    root $MAGE_ROOT;
    location ~ ^/le_connector/connector.php {

        ### This fixes the problem:
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        ################################

        fastcgi_pass   fastcgi_backend;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~ ^/le_connector/(?!pub/). {
        deny all;
    }

    location ~ ^/le_connector/pub/ {
        add_header X-Frame-Options "SAMEORIGIN";#
    }
}

with the file at $MAGE_ROOT/le_connector/connector.php

 

With selinux turned off it worked.

View solution in original post

2 REPLIES 2

Re: nginx config not allowing script in subdirectoy of $MAGE_ROOT/pub

Based on https://community.magento.com/t5/Magento-2-x-Technical-Issues/Magento-2-2-6-NGINX-add-additional-loc... - I also tried this in nginx.sample.conf:

 

# PHP entry point for le_connector application
location /le_connector {
    root $MAGE_ROOT;
    location ~ ^/le_connector/connector.php {

        ### This fixes the problem:
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        ################################

        fastcgi_pass   fastcgi_backend;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~ ^/le_connector/(?!pub/). {
        deny all;
    }

    location ~ ^/le_connector/pub/ {
        add_header X-Frame-Options "SAMEORIGIN";
    }
}

but https://mymagentodomain/le_connector/connector.php now returns:

"No input file specified."

Re: nginx config not allowing script in subdirectoy of $MAGE_ROOT/pub

So it turned out to be an selinux issue.  This addition to the nginx config was correct:

# PHP entry point for le_connector application
location /le_connector {
    root $MAGE_ROOT;
    location ~ ^/le_connector/connector.php {

        ### This fixes the problem:
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        ################################

        fastcgi_pass   fastcgi_backend;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~ ^/le_connector/(?!pub/). {
        deny all;
    }

    location ~ ^/le_connector/pub/ {
        add_header X-Frame-Options "SAMEORIGIN";#
    }
}

with the file at $MAGE_ROOT/le_connector/connector.php

 

With selinux turned off it worked.