Jump to content

Does PrestaShop 1.7 work with Nginx?


editview

Recommended Posts

Are there currently any working instructions for using PrestaShop 1.7 with Nginx?  I've seen several Nginx config files from people who have tried it, but none seem to work (either 404 or 500 errors).  It seems like most people end up giving up and using Apache?

Link to comment
Share on other sites

  • 2 weeks later...

I tried a few of those but still ended up with various errors.  Even if it did work, it all seems too fragile and basically just a hack since those configuration files set up special redirects for half a dozen of the Prestashop URLs, and if any of those Prestashop URLs change in future versions, or if new ones are added, the configuration file redirect hacks would have to be updated also.

I ended up switching to Apache.  I generally prefer Nginx, but I think Prestashop 1.7 just isn't set up to work well with it because Prestashop is doing something unusual with the way it handles URLs that causes issues with Nginx.

Edited by editview (see edit history)
Link to comment
Share on other sites

  • 1 month later...

I eventually gave up and had to switch the server to Apache.  

I'm not sure what PrestaShop is doing that is causing these issues but hopefully they'll fix it eventually so these special work arounds for Nginx are just no longer needed.

Link to comment
Share on other sites

Ok. Now it works perfectly and it's super fast since I also installed php-fmp w/ Nginx.

My issue was that I was including other config files without realizing it. Since I use easyengine that was done automatically but you need to remove all the includes.

Here is my config file:


server {


    server_name xxx.com   www.xxx.com;


    access_log /var/log/nginx/xxx.com.access.log rt_cache;
    error_log /var/log/nginx/xxx.com.error.log;


    root /var/www/xxx.com/htdocs;
    
    

    index index.php index.html index.htm;

    
    
    include /var/www/xxx.com/conf/nginx/*.conf;


    # [REQUIRED EDIT IF MULTILANG]
    rewrite ^/fr$ /fr/ redirect;
    rewrite ^/fr/(.*) /$1;

    rewrite ^/en$ /en/ redirect;
    rewrite ^/en/(.*) /$1;

    rewrite ^/qc$ /qc/ redirect;
    rewrite ^/qc/(.*) /$1;

 location / {
  index /index.php;
 
    # Global rewrite not depending on languages
  rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;

  rewrite "^/c/([0-9]+)(\-[_a-zA-Z0-9-]*)/(.*)\.jpg$" /img/c/$1$2.jpg last;
  rewrite "^/c/([_a-zA-Z-]+)/(.*)\.jpg$" /img/c/$1.jpg last;

  rewrite "^/([a-z0-9]+)\-([a-z0-9]+)(\-[_a-zA-Z0-9-]*)/(\P{M}\p{M}*)*\.jpg$" /img/p/$1-$2$3.jpg last;
  rewrite "^/([0-9]+)\-([0-9]+)/(\P{M}\p{M}*)*\.jpg$" /img/p/$1-$2.jpg last;
  rewrite "^/([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$1$2.jpg last;
  rewrite "^/([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$1$2$3.jpg last;
  rewrite "^/([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$3/$1$2$3$4.jpg last;
  rewrite "^/([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$3/$4/$1$2$3$4$5.jpg last;
  rewrite "^/([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg last;
  rewrite "^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg last;
  rewrite "^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8.jpg last;
  rewrite "^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg last;

  rewrite "^/([0-9]+)\-(\P{M}\p{M}*)+\.html(.*)$" /index.php?controller=product&id_product=$1$3 last;
  rewrite "^/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$" /index.php?controller=category&id_category=$1$3 last;
  rewrite "^/([a-zA-Z0-9-]*)/([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$" /index.php?controller=product&id_product=$2$4 last;
  rewrite "^/([0-9]+)__([a-zA-Z0-9-]*)(.*)$" /index.php?controller=supplier&id_supplier=$1$3 last;
  rewrite "^/([0-9]+)_([a-zA-Z0-9-]*)(.*)$" /index.php?controller=manufacturer&id_manufacturer=$1$3 last;
  rewrite "^/content/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$" /index.php?controller=cms&id_cms=$1$3 last;
  rewrite "^/content/category/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$" /index.php?controller=cms&id_cms_category=$1$3 last;
  rewrite "^/module/([_a-zA-Z0-9-]*)/([_a-zA-Z0-9-]*)$" /index.php?fc=module&module=$1&controller=$2 last;

  rewrite ^/page-not-found$ /index.php?controller=404 last;
  rewrite ^/address$ /index.php?controller=address last;  
  rewrite ^/addresses$ /index.php?controller=addresses last;
  rewrite ^/authentication$ /index.php?controller=authentication last;
  rewrite ^/best-sales$ /index.php?controller=best-sales last;
  rewrite ^/cart$ /index.php?controller=cart last;
  rewrite ^/contact-us$ /index.php?controller=contact-form last;
  rewrite ^/discount$ /index.php?controller=discount last;
  rewrite ^/guest-tracking$ /index.php?controller=guest-tracking last;
  rewrite ^/order-history$ /index.php?controller=history last;
  rewrite ^/identity$ /index.php?controller=identity last;
  rewrite ^/manufacturers$ /index.php?controller=manufacturer last;
  rewrite ^/my-account$ /index.php?controller=my-account last;
  rewrite ^/new-products$ /index.php?controller=new-products last;
  rewrite ^/order$ /index.php?controller=order last;
  rewrite ^/order-follow$ /index.php?controller=order-follow last;
  rewrite ^/quick-order$ /index.php?controller=order-opc last;
  rewrite ^/order-slip$ /index.php?controller=order-slip last;
  rewrite ^/password-recovery$ /index.php?controller=password last;
  rewrite ^/prices-drop$ /index.php?controller=prices-drop last;  
  rewrite ^/search$ /index.php?controller=search last;
  rewrite ^/sitemap$ /index.php?controller=sitemap last;
  rewrite ^/stores$ /index.php?controller=stores last;  
  rewrite ^/supplier$ /index.php?controller=supplier last;
  rewrite ^/[a-zA-Z][a-zA-Z]/index.php(.*)$ /index.php$1;

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


location /mymultistorename/ {
  rewrite ^/mymultistorename/(.*)$ /$1 last;
  try_files $uri $uri/ /index.php?$args;
}


    location /admin-dev/ { 
        if (!-e $request_filename) {
            rewrite ^/.*$ /admin-dev/index.php last;
        }
    }

 # PHP FPM part
    location ~ \.php$ {
        # Verify that the file exists, redirect to index if not
        try_files $fastcgi_script_name /index.php$uri&$args =404;

        fastcgi_index  index.php;

        # Environment variables for PHP
        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        include       fastcgi_params;

        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        # [REQUIRED EDIT] Connection to PHP-FPM - choose one
        # fastcgi_pass 127.0.0.1:9000;
        fastcgi_pass unix:/var/run/php7.0-fpm.sock;

        fastcgi_keep_conn on;
        fastcgi_read_timeout 30s;
        fastcgi_send_timeout 30s;

        # In case of long loading or 502 / 504 errors
        # fastcgi_buffer_size 256k;
        # fastcgi_buffers 256 16k;
        # fastcgi_busy_buffers_size 256k;
        client_max_body_size 10M;
    }

}
 

 

Link to comment
Share on other sites

  • 1 year later...
  • 4 months later...

indeed it's working but I get the error :

 

Warning: require_once(/home/nginx/domains/asd/public/var/cache/dev/appParameters.php): failed to open stream: Permission denied in /home/nginx/domains/asd/public/config/bootstrap.php on line 87

Fatal error: require_once(): Failed opening required '/home/nginx/domains/asd/public/var/cache/dev/appParameters.php'

 

file appParameters.php it's there but has no permission. I don't know how to investigate this ...

 

I have tried 

chown nginx:nginx /home/nginx/domains/yourdomain.com/public/wp chown -R nginx:nginx /home/nginx/domains/yourdomain.com/public/wp

 

but after some time happened again. I guess that it's being rewritten that file

Edited by dandumit (see edit history)
Link to comment
Share on other sites

  • 1 month later...
  • 5 months later...
On 3/18/2021 at 10:56 PM, dandumit said:

@arafatx - what control panel do you use ?  could you please share nginx configuration  ? on mine does not work with media servers. there is still to be added for CSS files.

Sorry for late reply. It's been few months. I actually use Directadmin control panel. When you use nginx_apache, the prestashop site run on nginx and you can use apache config. So it works out of box.

Link to comment
Share on other sites

17 minutes ago, dandumit said:

@El Patron could you share your configuration  ? When I am using ngnix reverese are disabled compression and also I think that should be added rules for serving images

Hi, we have linux black belt on our team who handles all our client hosting configurations.  also we use PLESK!  use PLESK people...much much much better than cpanel...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...