PrestaShop mit nginx

PrestaShop ist ein tolles eCommerce Tool abseits von WordPress. Die Basissoftware ist Open Source und läuft auch mit nginx. Es dauert zwar ein bisschen, bis man auf das richtige Gist mit der passenden Server Definition gestoßen ist, aber dann läuft alles rund.

Ich habe PrestaShop mit php7.1 getestet und hatte dabei keine Probleme. Nichts desto trotz bin ich wieder auf WordPress umgeschwenkt, da die AddOns bei PrestaShop einfach zu teuer und viel zu segmentiert sind: 40€ nur dafür, dass unten der Cookie Hinweis eingeblendet wird, ist etwas too much. Sofortüberweisungsmodul kostet dann z.B. 90€ oder DHL Verfolgung 100€. Das sind Preise, die kann nur ein mittelständischer Betrieb leisten, aber als Freelancer einfach unpassend.

Für kleinere Betriebe ist der Shop auf jeden Fall eine Überlegung wert. Eine größere Auswahl an passenden Themes gibt es auch zu kaufen – aber rechnet mit Investitionskosten in Höhe von ca. 500 – 1.000€, wenn ihr alle sinnvollen Plugins und ein Layout kaufen möchtet.

Unten nicht vergessen eure Werte zu setzen, z.B. bei admin directory. Im Produktivbetrieb natürlich auch einen SSL Block definieren und das SSL redirecting bitte über PrestaShop regeln – da ist die Software etwas empfindlich und es gibt ein SSL Setting dafür. Die PHP Definition genau anschauen! Hier habe ich einen apcu Cache Filter für den Adminbereich von Prestashop gesetzt – bitte den Pfad zu eurem Adminbereichordner entsprechend ändern.
Dafür bei Prestashop bitte den apcu Cache nehmen und vorher das php Modul installieren. Wenn ihr dann keinen Filter für den Adminbereich installiert, fliegt euch bei Prestashop um die Ohren, sobald ihr in den Wartungsmodus wechselt und das Template editiert.

php Config


[presta]

listen = /var/run/php/php7.1-fpm-presta.sock
listen.allowed_clients = 127.0.0.1

user = presta
group = presta
listen.mode = 0660
listen.owner = presta
listen.group = www-data

pm = dynamic
pm.max_children = 15
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 7

chdir = /

php_admin_value[open_basedir] = /var/customers/prestashop/httpdocs:/usr/share/php:/tmp:/var/tmp:/var/ngx_pagespeed_cache
php_admin_value[disable_functions] = dl,passthru,shell_exec,system,proc_open,popen,show_source
php_admin_value[memory_limit] = 256M
php_admin_value[max_execution_time] = 360
php_admin_value[short_open_tag] = off
php_admin_value[apc.filters]= "-/var/www/prestashop/httpdocs/admin132raenii/.*"

nginx Config


server {
    listen 80;
    listen [::]:80;            # Uncomment this line if you also want to enable IPv6 support
    server_name test.shop;
    root /var/customers/prestashop/httpdocs;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
 
    location = /favicon.ico {
        log_not_found off;      # PrestaShop by default does not provide a favicon.ico
        access_log off;         # Disable logging to prevent excessive log sizes
    }
 
     location = /robots.txt {
         auth_basic off;        # Whatever happens, always let bots know about your policy
         allow all;
         log_not_found off;     # Prevent excessive log size
         access_log off;
    }
 
    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
    # Your admin folder
    set $admin_dir /admin132raenii;

    # Gzip Settings, convert all types.
    gzip on;
    gzip_vary on;
    gzip_proxied any;

    # Can be enhance to 5, but it can slow you server
    # gzip_comp_level    5;
    # gzip_min_length    256;

    gzip_types
        application/atom+xml
        application/javascript
        application/json
        application/ld+json
        application/manifest+json
        application/rss+xml
        application/vnd.geo+json
        application/vnd.ms-fontobject
        application/x-font-ttf
        application/x-web-app-manifest+json
        application/xhtml+xml
        application/xml
        font/opentype
        image/bmp
        image/svg+xml
        image/x-icon
        text/cache-manifest
        text/css
        text/plain
        text/vcard
        text/vnd.rim.location.xloc
        text/vtt
        text/x-component
        text/x-cross-domain-policy;
        # Supposed to be the case but we never know
        # text/html;
        
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    # Old image system ?</pre>

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&amp;id_product=$1$3 last;
 rewrite "^/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$" /index.php?controller=category&amp;id_category=$1$3 last;
 rewrite "^/([a-zA-Z0-9-]*)/([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$" /index.php?controller=product&amp;id_product=$2$4 last;
 rewrite "^/([0-9]+)__([a-zA-Z0-9-]*)(.*)$" /index.php?controller=supplier&amp;id_supplier=$1$3 last;
 rewrite "^/([0-9]+)_([a-zA-Z0-9-]*)(.*)$" /index.php?controller=manufacturer&amp;id_manufacturer=$1$3 last;
 rewrite "^/content/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$" /index.php?controller=cms&amp;id_cms=$1$3 last;
 rewrite "^/content/category/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$" /index.php?controller=cms&amp;id_cms_category=$1$3 last;
 rewrite "^/module/([_a-zA-Z0-9-]*)/([_a-zA-Z0-9-]*)$" /index.php?fc=module&amp;module=$1&amp;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;

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

    # Redirect needed to "hide" index.php
    location / {
        try_files $uri $uri/ /index.php$uri&amp;amp;$args;
        index index.php index.html index.htm
    }

    error_page 404 /index.php?controller=404;

    # Static assets delivery optimisations
    add_header Strict-Transport-Security max-age=31536000;

    # Cloudflare / Max CDN fix
    location ~* \.(eot|otf|ttf|woff|woff2)$ {
        add_header Access-Control-Allow-Origin *;
    }

    location ~* \.(css|js|docx|zip|pptx|swf|txt|jpg|jpeg|png|gif|swf|webp|flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|mp4|m4v|ogg|webm|aac)$ {
      expires max;
      log_not_found off;
      add_header Pragma public;
      add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }

    # Deny access to .htaccess .DS_Store .htpasswd etc
    location ~ /\. {
        deny all;
    }

    # Security for your themes
    location ~ \.tpl {
        deny all;
    }

    # PHP 7 FPM part
    location ~ [^/]\.php(/|$) {
        fastcgi_index index.php;

        # Switch if needed
        include /etc/nginx/fastcgi_params;
        #include fcgi.conf;

        # Do not forget to update this part if needed
        # fastcgi_pass 127.0.0.1:9000;
        fastcgi_pass unix:/var/run/php/php7.1-fpm-presta.sock;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        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;

        # Temp file tweak
        fastcgi_max_temp_file_size 0;
        fastcgi_temp_file_write_size 256k;
   }
}

beispieldefinitioninstallierenkonfignginxphp7Prestashopvhost
Comments (0)
Add Comment