Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PrestaShop Nginx Configuration
server {
listen 80;
listen [::]:80; #Use this to enable IPv6
server_name www.example.com;
root /var/www/prestashop17;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
index index.php index.html;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
auth_basic off;
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;
}
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 1;
gzip_buffers 16 8k;
gzip_http_version 1.0;
gzip_types application/json text/css application/javascript;
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.jpg last;
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;
rewrite ^/order$ /index.php?controller=order last;
location /admin-dev/ { #Change this to your admin folder
if (!-e $request_filename) {
rewrite ^/.*$ /admin-dev/index.php last; #Change this to your admin folder
}
}
location / {
if (!-e $request_filename) {
rewrite ^/.*$ /index.php last;
}
}
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.*)$;
try_files $uri =404;
fastcgi_keep_conn on;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000; #Change this to your PHP-FPM location
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Thank you Mickeal Dekker: https://www.prestashop.com/forums/topic/519123-config-prestashop-17-and-nginx/
@cdoublev

This comment has been minimized.

Copy link

commented Feb 23, 2018

Hi Julien,

I'm not sure if it's the right place to say this, but I think you should document somewhere that setting any caching related HTTP header for html files will cause 404 when using ".html" in permalinks, which I think is what's currently used by default in PS 1.6/1.7 for product pages.

I was copying the popular H5BP Nginx template, which is using Cache-Control: max-age=0; for html files. It took me some time to figuring out why I was always getting back 404 responses.

I don't see any Nginx configuration workaround, and I asked myself why H5BP is adding this header (my browser Chrome is sending request with Cache-control: no-cache"). It seems that's a good practice in regard to RFC 7234.

EDIT: in case it isn't immediately clear (as it was for me, 10 month after posting this comment) why a location such as location ~* \.(?:manifest|appcache|html?|xml|json)$ (used in H5BP Nginx template to set Cache-Control: max-age=0) is causing a 404 in Prestashop for product pages or any page suffixed with .html, it's because it will prevent any further work from Nginx to process the request (sending it to PHP).

@zhiyicai

This comment has been minimized.

Copy link

commented Apr 6, 2018

Hi Julien,
Prestashop 1.7 admin worked well except for the Module sections, probably because the url has a different structure like:
http://www.demo.com/admin/index.php/module/catalog?_token=zBZuz_fhR_OOaCO9m_wq7_IlOZrSgQ5PM4bm4C5XQZU
Erro code 400
How can I solve it?

@Klemart3D

This comment has been minimized.

Copy link

commented Aug 20, 2018

    # Symfony controllers
    location ~ /(international|_profiler|product|feature|attribute|supplier|combination|specific-price)/(.*)$ {
          try_files $uri $uri/ /index.php?q=$uri&$args $admin_dir/index.php$is_args$args;        
    }
	
@mvandeplassche

This comment has been minimized.

Copy link

commented Nov 14, 2018

I've had trouble with symfony controllers specific rules regarding ajax calls to refresh the cart preview.
If I keep them, there is a conflict with ajax call to /module/ps_shoppingcart/ajax.

If I remove them, it's all working on the front end but module page on the back end returns 404.
FYI had better success with this : https://github.com/PrestaShop/PrestaShop/blob/develop/docs/server_config/nginx.conf.dist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.