2012-09-29 73 views
4

出於性能原因,我想從Apache更改爲Nginx + Php-Fpm。目前我可以看到我的網站的主頁(在測試環境中),但是現在在Apache中工作的任何友好的URL都不起作用。Nginx重寫prestashop的規則,如何設置,調試和啓用?

我已經將規則轉換爲nginx規則,但是我沒有任何方法來測試它,因爲每次點擊網站的某個url會變成我的瀏覽器下載php文件!

例如

我點擊www.misite.com/autentication和我的瀏覽器下載一個php文件: -/

環境試驗是

  • PHP 5.3.17(CLI )(built:Sep 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的版本:nginx的/ 1.0.15

這是我的Nginx虛擬主機配置:

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; 
     } 
} 

最嚴重的問題是我沒有一些經驗調試問題: -/nginx的 任何評論很新的可以理解的,

感謝

+0

PS:其實,行爲是一樣的URL /認證,使瀏覽器TU下載文件和URL像/some-product.html得到一個404錯誤,所以,我可以確認重寫不起作用:( – Rubendob

+0

你能提一下它的prestashop版本嗎? –

回答

4

好吧,我已經解決我自己的問題!這是順便說那麼容易,不僅是改變

我感動的

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

所有規則

server { 

...here rules works... 

} 

然後我重新加載nginx的,這就是它的規則的位置!

服務nginx的重裝

我希望這能爲像我這樣的一些絕望的人是有用的。

最好的問候,