Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save degouville/7e3b37780b6936502bb30f1c574dc580 to your computer and use it in GitHub Desktop.

Select an option

Save degouville/7e3b37780b6936502bb30f1c574dc580 to your computer and use it in GitHub Desktop.
✅ A working configuration for Nginx + PHP-FPM from PHPBrew for Prestashop Multisites with URL Rewriting
server {
server_name myshopdomain.com;
root /var/www/myshopdomain.com;
index index.html index.php;
# Multisite indexes - Define a new `index` for each sites
location /shop-one/ {
try_files $uri $uri/ /shop-one/index.php?$args;
}
location /shop-two/ {
try_files $uri $uri/ /shop-two/index.php?$args;
}
# Prestashop URL Rewriting rules
rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /img/p/$1/$1$2.jpg last;
rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /img/p/$1/$2/$1$2$3.jpg last;
rewrite ^/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.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-]*)?/[_a-zA-Z0-9-]*.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-]*)?/[_a-zA-Z0-9-]*.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-]*)?/[_a-zA-Z0-9-]*.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-]*)?/[_a-zA-Z0-9-]*.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-]*)?/[_a-zA-Z0-9-]*.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg last;
rewrite ^/c/([0-9]+)(-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*.jpg$ /img/c/$1$2.jpg last;
rewrite ^/c/([a-zA-Z-]+)/[a-zA-Z0-9-]+.jpg$ /img/c/$1.jpg last;
rewrite ^/([0-9]+)(-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*.jpg$ /img/c/$1$2.jpg last;
rewrite ^/[a-zA-Z][a-zA-Z]/index.php(.*)$ /index.php$1;
try_files $uri $uri/ /index.php?$args;
# PHP-FPM config - Use the proper PHP version installed globally using PHPBrew
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/opt/phpbrew/php/php-X.X.XX/var/run/php-fpm.sock;
}
# Ignore dot files (like .htaccess)
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
access_log /var/log/nginx/myshopdomain.access.log;
error_log /var/log/nginx/myshopdomain.error.log;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/myshopdomain.degouville.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/myshopdomain.degouville.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = myshopdomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name myshopdomain.com;
return 404; # managed by Certbot
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment