出于性能原因,我想从 Apache 更改为 Nginx+Php-Fpm。目前我可以看到我网站的主页(在测试环境中),但任何在 Apache 中工作的友好 url 现在都不起作用。
我已经将规则转换为 nginx 规则,但我没有任何方法来测试它,因为每次点击网站的某个 url 都会变成我的浏览器下载 php 文件!
例如
我点击 www.misite.com/autentication 和我的浏览器下载一个 php 文件:-/
环境测试是
PHP 5.3.17 (cli)(构建时间:2012 年 9 月 13 日 06:45:07)版权所有 (c) 1997-2012 The PHP Group Zend Engine v2.3.0,版权所有 (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 非常新 任何评论将不胜感激,
谢谢