Acinonyx Web Agency

Boost your PrestaShop with our Nginx configuration

Scroll down to Discover

Optimal Nginx configuration for PrestaShop 1.7

Optimal Nginx configuration for PrestaShop 1.7

Many of you want to run your e-commerce store on a high-performance server using Nginx.

However, today no official configuration has been shared by PrestaShop. This is why multiple different configurations are shared online, but most of them are not complete or suitable for every installation.

This is why we are sharing with you today our Nginx configuration template for PrestaShop. This template is doomed to evolve and if you want to have the latest version, go to our COO’s GitHub.

 

Configure a Nginx vHost for Prestashop 1.7

Here is the template that you can use, while modifying the following variables:

  • {domain}
  • {directory}
  • {admin-directory}

If you do not know, or are unable to integrate this configuration, contact us so that we could do it for you.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
###############
# HTTPS VHOST #
###############

server {
        ######################
        # REGULAR PARAMETERS #
        ######################

        server_name {domain};

        root {directory};
        index index.php;

        listen [::]:443 ssl ipv6only=on;
        listen 443 ssl;

        # Comment this if you are not using Certbot
        ssl_certificate /etc/letsencrypt/live/{domain}/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/{domain}/privkey.pem;
        include /etc/letsencrypt/options-ssl-nginx.conf; 
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; 

        error_log /var/log/nginx/{domain}.error;


        ########################
        # LOCATION DIRECTIVES #
        ########################

        # PHP Status monitor, uncomment if needed (you have to enable it in your PHP-FPM pool config)
        # location ~ ^/(status|ping)$ {
        #        allow 127.0.0.1;
        #        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #        fastcgi_index index.php;
        #        include fastcgi_params;
        #        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
        # }

        # Change this to your default admin path (for ex. /admin-mywebsite ; prefix the URL with a "/")
        set $admin_dir {admin-directory};

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

        # Default locations
        location / {
                try_files $uri $uri/ /index.php$uri&$args;
        }

        # Use only one of the following php location according to your PHP configuration
        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;

                # Optimized for CloudFlare CDN, if you are not using it you can increase theses variables according to your needs
                fastcgi_keep_conn on;
                fastcgi_read_timeout 100s;
                fastcgi_send_timeout 100s;
                client_max_body_size 20M;
                fastcgi_max_temp_file_size 0;
                fastcgi_temp_file_write_size 512k;

                # Change this for your PHP socket
                fastcgi_pass unix:/run/php/php7.3-fpm.sock;
        }

        # If the PHP directive from the top didn't work, use the following one:
        #    location ~ \.php$ {
        #       try_files $uri =404;
        #       fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       fastcgi_pass unix:/run/php/php7.3-fpm.sock;
        #       fastcgi_index index.php;
        #       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #       include fastcgi_params;
        #    }

        location ~* \.(eot|otf|ttf|woff|woff2)$ {
                add_header Access-Control-Allow-Origin *;
        }

        location ~* ^.+\.(css|js|ogg|ogv|svg|svgz|eot|otf|woff|woff2|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
                access_log off;
                log_not_found off;
                expires max;
                add_header Pragma public;
                add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        }

        location ~* \.(pdf)$ {
                expires 30d;
        }

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

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

        # File security
        # .htaccess .DS_Store .htpasswd etc
        location ~ /\. {
            deny all;
        }

        # Source code directories
        location ~ ^/(app|bin|cache|classes|config|controllers|docs|localization|override|src|tests|tools|translations|travis-scripts|vendor|var)/ {
            deny all;
        }

        location ~ \.(htaccess|yml|log|twig|sass|git|tpl)$ {
                deny all;
        }

        # vendor in modules directory
        location ~ ^/modules/.*/vendor/ {
            deny all;
        }

        # Prevent exposing other sensitive files
        location ~ \.(yml|log|tpl|twig|sass)$ {
            deny all;
        }

        # Prevent injection of php files
        location /upload {
            location ~ \.php$ {
                deny all;
            }
        }

        location /img {
            location ~ \.php$ {
                deny all;
            }
        }


        ######################
        # REWRITE DIRECTIVES #
        ######################

        # Uncomment & edit this if you are using multilanguage (preset for french here)
        # rewrite ^/fr$ /fr/ redirect;
        # rewrite ^/fr/(.*) /$1;

        # Rewrite for admin directory
        location $admin_dir/ {
            if (!-e $request_filename) {
                rewrite ^/.*$ $admin_dir/index.php last;
            }
        }

        # Images
        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;

        # AlphaImageLoader for IE and fancybox
        rewrite ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 last;

        # Web service API
        rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;

        # Installation sandbox
        rewrite ^(/install(?:-dev)?/sandbox)/(.*) /$1/test.php last;

        # Products and regular pages
        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;

        # EN rewrites
        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 ^/brand$ /index.php?controller=manufacturer last;
        rewrite ^/brand/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$ /index.php?id_manufacturer=$1&controller=manufacturer;
        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 ^/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 ^/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 ^/order-follow$ /index.php?controller=order-follow last;
        rewrite ^/order-history$ /index.php?controller=history last;
        rewrite ^/order-slip$ /index.php?controller=order-slip last;
        rewrite ^/page-not-found$ /index.php?controller=404 last;
        rewrite ^/password-recovery$ /index.php?controller=password last;
        rewrite ^/quick-order$ /index.php?controller=order-opc last;
        rewrite ^/search$ /index.php?controller=search last;
        rewrite ^/stores$ /index.php?controller=stores last;
        rewrite ^/supplier$ /index.php?controller=supplier last;

        # FR rewrites
        rewrite ^/adresse$ /index.php?controller=address last;
        rewrite ^/adresses$ /index.php?controller=addresses last;
        rewrite ^/avoirs$ /index.php?controller=order-slip last;
        rewrite ^/commande$ /index.php?controller=order last;
        rewrite ^/commande-rapide$ /index.php?controller=order-opc last;
        rewrite ^/comparaison-produits$ /index.php?controller=products-compare last;
        rewrite ^/confirmation-commande$ /index.php?controller=order-confirmation last;
        rewrite ^/connexion$ /index.php?controller=authentication last;
        rewrite ^/fabricants$ /index.php?controller=manufacturer last;
        rewrite ^/fournisseur$ /index.php?controller=supplier last;
        rewrite ^/fournisseurs$ /index.php?controller=supplier last;
        rewrite ^/historique-commandes$ /index.php?controller=history last;
        rewrite ^/identite$ /index.php?controller=identity last;
        rewrite ^/magasins$ /index.php?controller=stores last;
        rewrite ^/meilleures-ventes$ /index.php?controller=best-sales last;
        rewrite ^/mon-compte$ /index.php?controller=my-account last;
        rewrite ^/nous-contacter$ /index.php?controller=contact-form last;
        rewrite ^/nouveaux-produits$ /index.php?controller=new-products last;
        rewrite ^/page-introuvable$ /index.php?controller=404 last;
        rewrite ^/panier$ /index.php?controller=cart last;
        rewrite ^/plan-site$ /index.php?controller=sitemap last;
        rewrite ^/promotion$ /index.php?controller=discount last;
        rewrite ^/promotions$ /index.php?controller=prices-drop last;
        rewrite ^/recherche$ /index.php?controller=search last;
        rewrite ^/recuperation-mot-de-passe$ /index.php?controller=password last;
        rewrite ^/reduction$ /index.php?controller=discount last;
        rewrite ^/sitemap$ /index.php?controller=sitemap last;
        rewrite ^/suivi-commande$ /index.php?controller=order-follow last;
        rewrite ^/suivi-commande-invite$ /index.php?controller=guest-tracking last;
}


#################
# HTTP REDIRECT #
#################

server {
    server_name {domain};

    if ($host = {domain}) {
        return 301 https://$host$request_uri;
    }
    
    listen 80;
    listen [::]:80;

    return 404;
}

 

If you are having trouble integrating this solution, or if you want to further optimize your PrestaShop, contact our team of experts. We have other techniques that we have developed in-house that can help you boost the speed of your site.

 

Acinonyx Hosting

Acinonyx Hostingefficient web hosting

 

You don’t want to burden yourself with all the technical part? So call on our bulletproof web hosting service, specializing in the configuration/maintenance of high-performance servers, in addition to ensuring compatibility with all CMS such as PrestaShop & WordPress.

Specifications of your project

Specifications of your project

Follow the different steps to generate the specifications of your project

LET'S GO

Congratulations we have sent you your specifications by email and we will get back to you shortly!

About your project

What is your project objective?

Server Icon
Sync Icon
Database Solid
You need to select an item to continue

Server optimization

What do you want us to optimize?




You need to select an item to continue

Server configuration

What features would you like us to implement?








You need to select an item to continue

Tell us more about your server

We need to know the specs of your server to know how we could help you

What is its operating system, CPU, RAM & drive capacity etc. And also the packets that you have installed (Apache, Nginx, PHP...). If you don't have a server yet, please tell us.

You need to select an item to continue

Your specifications has been generated

Your project is estimated to:

But by using this simulator you gain 10% reduction with the code CHEETAH10!

Summary

Description Information Quantity Price
Discount :
Total :
Logo T

Thomas

COO & lead developer

Holding of the 2019 cyber-jurist award young IT talent, Thomas is a french very well known developer for his work on Hootis. Websites, algorithms, scripts and API development…

There is no difficulty for me, only challenges to overcome.

Nothing scares him! He is in charge of the most ambitious & difficult projects with a multidisciplinary team from Europe selected as one of the best.

Contact