20 Apr

Prestashop NGINX Configuration

prestashop nginx config example:

As Prestashop is widely used in the ecommerce business we thought it would nice to add a nginx configuration for prestashop.

We have tested nginx + php-fpm in combination vs apache and must say the result favors of nginx are outstanding :-)

Never seen prestashop respond so fast :-)

Below is a snippet of the nginx config for a vhost for running prestashop in combination of PHP-FPM:

 

server {
listen yourserverip:80;
server_name prestashop.prohost.be;
root /home/path/toyour/prestashop;

# uncomment the 3 lines below if you want a perm redirect to www

# if ($http_host != “www.prestshop.com”) {
# rewrite ^ http://www.prestashop.com$request_uri permanent;
# }

index index.html index.php;

location = /favicon.ico {
log_not_found off;
access_log off;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /. {
deny all;
access_log off;
log_not_found off;
}

rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$1$2$3.jpg last;
rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$1$2$3$4.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$5.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$6.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$7.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$8.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$9.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$10.jp$
rewrite ^/c/([0-9]+)(-[.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+.jpg$ /img/c/$1$2$3.jpg last;
rewrite ^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+.jpg$ /img/c/$1$2.jpg last;
rewrite ^/images_ie/?([^/]+).(jpe?g|png|gif)$ /js/jquery/plugins/fancybox/images/$1.$2 last;
try_files $uri $uri/ /index.php$is_args$args;
error_page 404 /index.php?controller=404;

 

 

location ~* .(gif)$ {
expires 2592000s;
}
location ~* .(jpeg|jpg)$ {
expires 2592000s;
}
location ~* .(png)$ {
expires 2592000s;
}
location ~* .(css)$ {
expires 604800s;
}
location ~* .(js|jsonp)$ {
expires 604800s;
}
location ~* .(js)$ {
expires 604800s;
}
location ~* .(ico)$ {
expires 31536000s;
}

 

location ~ .php$ {
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
}

 

Close and save the file and restart nginx.

Your prestashop should be running lightning fast with nginx and php-fpm.
Above configuration has been tested and verified for prestashop 1.5.3

 

Depending on your version you may need to modify the configuration to work.

More information can be found in prestashop forums:

http://www.prestashop.com/forums/

And on the nginx wiki

http://wiki.nginx.org/Main

 

 

Share this