Skip to content

Instantly share code, notes, and snippets.

@pranid
Created August 16, 2016 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pranid/28a52dd8b4cc5fcb7ecfae96254863e6 to your computer and use it in GitHub Desktop.
Save pranid/28a52dd8b4cc5fcb7ecfae96254863e6 to your computer and use it in GitHub Desktop.
Nginx Server Configuration file for Prestashop
server {
listen 80; ## listen for ipv4; this line is default and implied
listen [::]:80; ## listen for ipv6
# Replace/ set your directory path here
root /var/www/html/prestashop;
index index.html index.htm index.php;
# Make site accessible from http://localhost/
server_name yourhost.com;
# Needed by the installer
location = /install/sandbox/anything.php {
rewrite .* /install/sandbox/test.php last;
}
# Pass API requests to the webservice dispatcher
location ^~ /api/ {
rewrite ^/api/(.*) /webservice/dispatcher.php?url=$1 last;
}
# Block all files starting with ., like .htaccess
location ~ /\. {
deny all;
}
# Block all files with these extensions
location ~ \.(md|tpl)$ {
deny all;
}
# Directories explicitly allowed in directories blocked below
location ~ ^/docs/csv_import/ {
allow all;
}
# Block everything else in these directories
location ~ ^/(admin666/backups|admin666/export|admin666/import|admin666/tabs|classes|config|docs|download|install666|localization|log|override|tools|translations)/ {
deny all;
}
# 1 month expiry on other static stuff
# Also do the friendly URL rewrites
location ~* \.(eot|gif|ico|jpg|jpeg|otf|pdf|png|svg|swf|ttf|woff)$ {
rewrite ^/([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$1$2$3.jpg break;
rewrite ^/([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$1$2$3$4.jpg break;
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 break;
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 break;
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 break;
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 break;
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 break;
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 break;
rewrite ^/c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2$3.jpg break;
rewrite ^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg break;
rewrite ^/images_ie/?([^/]+)\.(jpe?g|png|gif)$ /js/jquery/plugins/fancybox/images/$1.$2 break;
# next line is PSCSX-2790 bug workaround, fixed in 1.6.0.10
rewrite ^/[a-zA-Z]+/img/cms/(.*)$ /img/cms/$1 break;
expires 1M;
add_header Cache-Control public;
allow all;
}
# Block everything else in these directories
location ~ ^/img/cms/ {
deny all;
}
# 1 week expiry on CSS and JavaScript
location ~ \.(css|js)$ {
expires 1w;
add_header Cache-Control public;
allow all;
}
# PHP :: Please check the php version
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
# The rest is either served directly or passed on to the dispatcher
location / {
try_files $uri $uri/ /index.php?$args;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment