Nginx – Directory index of /var/www/html/opencart is forbidden Nginx

nginxPHP

I have install multiple php frameworks (Cakephp and Opencart) on nginx web server. Cakephp is working fine in root directory. Opencart is in subdirectory in where i am getting errors.
Here is my nginx config file.

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name dev.test.com;
    return         301 https://$server_name$request_uri;

    root /var/www/html/app/webroot/;

    index index.php index.html index.htm index.nginx-debian.html;


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

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
            }

}

server {

    listen 443 ssl; # managed by Certbot

    ssl_certificate /etc/letsencrypt/live/dev.test.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/dev.test.com/privkey.pem; # managed by Certbot

    root /var/www/html/app/webroot;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    include snippets/phpmyadmin.conf;
    server_name dev.test.com;

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

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
            fastcgi_intercept_errors on;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
    }

    location /estore/ {
            alias /var/www/html/estore;
            index index.html index.htm index.php;
            try_files $uri $uri/ @opencart;
    }

    location @opencart {
            rewrite ^/(.+)$ /index.php?_route_=$1 last;
    }

}

Best Answer

Try this:

    location ^~ /estore {
            root /var/www/html;
            index index.php index.html index.htm;
            try_files $uri $uri/ @opencart;
            location ~ \.php$ {
                    include snippets/fastcgi-php.conf;
                    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
                    fastcgi_intercept_errors on;
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
            }
    }

    location @opencart {
            rewrite ^/(.+)$ /estore/index.php?_route_=$1 last;
    }