0

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;
    }

}

  • Are you sure this is the server block corresponding to your request? It doesn't match your error message. Please post the output of nginx -T. – Michael Hampton Jun 29 at 19:05
1

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;
    }
| improve this answer | |
  • It shows 404 Not Found – gurupal singh Jun 29 at 18:41
  • @gurupalsingh Got it, all php requests going to the location ~ \.php$ { ... } where $document_root equals to /var/www/html/app/webroot. Please check an updated answer. – Ivan Shatsky Jun 29 at 18:54
  • @gurupalsingh And this config assumes you have your opencart installation in /var/www/html/estore, not the /var/www/html/opencart. – Ivan Shatsky Jun 29 at 18:58
  • it worked but .. but the site is get loading and loading. It shows 504 (Gateway Time-out) now – gurupal singh Jun 29 at 19:02
  • @gurupalsingh Are the first and the second php locations equal? In my first edit I used php location from your first server block by mistake. – Ivan Shatsky Jun 29 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.