Jump to content

Prestashop configuration with Apache and Nginx


kaiservikingo

Recommended Posts

Dear everyone,

 

I'm trying to configure prestashop with Apache 2.4 and Nginx on Ubuntu 16.04.

The goal is to serve the static content with Nginx and the .php file would be processed by Apache (php-fpm).

The installation was done following this tutorial Here

The problems experienced now are the following:

- I have several language/locations configure for my website so the url xxx.xxxxxxxx.xxx should be redirected to xxx.xxxxxxxx.xxx/es/  (spanish). But when I try to access to the url the page start to redirect (301 http message) in loop till time-out/fail. (image attached)

- If I disable the friendly URLs the website works but extremely slow. (Enabling friendly URLs the issue above explained)

- The mod_rewrite is enabled

- The Nginx should send all php file to the port 8080 (where apache is listen) and then Apache process them.

- The apache site configuration (image attached)

- The nginx site configuration  (image attached)

 

Do anyone how to solve this? Any advice / trick will be welcome.

 

Thanks in advance

Kind Regards

KV.

error.png

apache_site_conf.png

nginx_site_conf.png

Link to comment
Share on other sites

  • 2 weeks later...

Hi Kaiservikingo,

we have experienced the same problem, and we have solved just by adding the following line to the configuration suggested by prestashop, just before the try_files line:

rewrite '^/([a-z]{2})/(.*)' /index.php?isolang=$1&$args last;

 

This line avoid the loops and redirect the page to the correct language, without disabling URL rewriting.

So the full nginx configuration will be:
 

rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$1$2.jpg last;
rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$1$2$3.jpg last;
rewrite ^/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.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-]*)?(-[0-9]+)?/.+\.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-]*)?(-[0-9]+)?/.+\.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-]*)?(-[0-9]+)?/.+\.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-]*)?(-[0-9]+)?/.+\.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-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg last;
rewrite ^/c/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
rewrite ^/c/([a-zA-Z-]+)(-[0-9]+)?/.+\.jpg$ /img/c/$1.jpg last;
rewrite ^/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
rewrite '^/js/(.*)' /js/$1 last;  #prevent issues with /js folder
rewrite '^/([a-z]{2})/(.*)' /index.php?isolang=$1&$args last;
try_files $uri $uri/ /index.php?isolang=$1&$args;

 

I hope that this configuration can help to solve your problem.

Best regards.

Antonio Cicirelli

Ideacommerce.it

Edited by antoniocici (see edit history)
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...