Nginx rewrite rules for prestashop, how to configure, debug and enable?

I want to change from Apache to Nginx + Php-Fpm for performance reasons. Currently, I can see the homepage of my website (in a test environment), but any friendly URL that worked in Apache now does not work.

Iโ€™ve already converted the rules to nginx rules, but I donโ€™t have the opportunity to check it, because every click on some website URL turns into my browser downloading the php file!

eg

I click on www.misite.com/autentication and my browser downloads the php file: - /

Environment test

  • PHP 5.3.17 (cli) (built: September 13, 2012 06:45:07) Copyright (c) 1997-2012 PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

  • nginx -v nginx version: nginx / 1.0.15

Here is my nginx virtual host configuration:

server { server_name site.com www.site.com; root /srv/www/site.com/httpdocs; access_log /srv/www/site.com/log/access.log; error_log /srv/www/site.com/log/error.log; rewrite_log on; location / { index index.html index.htm index.php; rewrite ^/([a-z0-9]+)\-([a-z0-9]+)(\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\.jpg$ /img/p/$1-$2$3.jpg? break; rewrite ^/([0-9]+)\-([0-9]+)/[_a-zA-Z0-9-]*\.jpg$ /img/p/$1-$2.jpg? break; rewrite ^/([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$ /img/p/$1/$1$2.jpg? break; rewrite ^/([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$ /img/p/$1/$2/$1$2$3.jpg? break; 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? break; 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? break; 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? break; 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? break; 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? break; 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? break; rewrite ^/c/([0-9]+)(\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\.jpg$ /img/c/$1$2.jpg? break; rewrite ^/c/([a-zA-Z-]+)/[a-zA-Z0-9-]+\.jpg$ /img/c/$1.jpg? break; rewrite ^/([0-9]+)(\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\.jpg$ /img/c/$1$2.jpg? break; rewrite ^/([0-9]+)\-[a-zA-Z0-9-]*\.html /product.php?id_product=$1 break; rewrite ^/[a-zA-Z0-9-]*/([0-9]+)\-[a-zA-Z0-9-]*\.html /product.php?id_product=$1 break; rewrite ^/([0-9]+)\-[a-zA-Z0-9-]*(/[a-zA-Z0-9-]*)+ /category.php?id_category=$1&noredirect=1 break; rewrite ^/([0-9]+)\-[a-zA-Z0-9-]* /category.php?id_category=$1 break; rewrite ^/([0-9]+)__([a-zA-Z0-9-]*) /supplier.php?id_supplier=$1 break; rewrite ^/([0-9]+)_([a-zA-Z0-9-]*) /manufacturer.php?id_manufacturer=$1 break; rewrite ^/content/([0-9]+)\-([a-zA-Z0-9-]*) /cms.php?id_cms=$1 break; rewrite ^/content/category/([0-9]+)\-([a-zA-Z0-9-]*) /cms.php?id_cms_category=$1 break; rewrite ^/pagina-no-encuentra$ /404.php break; rewrite ^/direccion$ /address.php break; rewrite ^/direcciones$ /addresses.php break; rewrite ^/autenticacion$ /authentication.php break; rewrite ^/mas-vendidos$ /best-sales.php break; rewrite ^/carro-de-la-compra$ /cart.php break; rewrite ^/contactenos$ /contact-form.php break; rewrite ^/descuento$ /discount.php break; rewrite ^/estado-pedido$ /guest-tracking.php break; rewrite ^/historial-de-pedidos$ /history.php break; rewrite ^/identidad$ /identity.php break; rewrite ^/fabricantes$ /manufacturer.php break; rewrite ^/mi-cuenta$ /my-account.php break; rewrite ^/nuevos-productos$ /new-products.php break; rewrite ^/carrito$ /order.php break; rewrite ^/devolucion-de-productos$ /order-follow.php break; rewrite ^/pedido-rapido$ /order-opc.php break; rewrite ^/vales$ /order-slip.php break; rewrite ^/contrasena-olvidado$ /password.php break; rewrite ^/promocion$ /prices-drop.php break; rewrite ^/buscar$ /search.php break; rewrite ^/mapa-del-sitio$ /sitemap.php break; rewrite ^/tiendas$ /stores.php break; rewrite ^/proveedores$ /supplier.php break; error_page 404 = /404.php; } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } 

Worst problem: I have no experience to debug the problem: - / Very new with Nginx Any comment would be appreciated,

thanks

+4
source share
1 answer

Ok, I fixed my problem! It was so easy, by the way, there was only a change of location of the rules.

I moved all the rules

 location /{ .... rules... } 

to

 server { ...here rules works... } 

Then I restart nginx and this!

nginx reload service

Hope this can be useful for some desperate guy like me.

Yours faithfully,

Ruben

+4
source

Source: https://habr.com/ru/post/1436963/


All Articles