Nginx重写到以前的目录

我试图将我的博客从blog.example.com移动到example.com/blog来做到这一点我宁愿不移动磁盘上的任何东西,所以我改变了我的nginxconfiguration文件如下:

location /blog { if (!-e $request_filename) { rewrite ^.*$ /index.php last; } root /home/demo/public_html/blog.example.com/current/public/; index index.php index.html index.html; passenger_enabled off; index index.html index.htm index.php; try_files $uri $uri/ @blog; } 

这工作很好,但是当我访问example.com/blog nginx寻找:

 /home/demo/public_html/blog.example.com/current/public/blog/index.php 

代替

 /home/demo/public_html/blog.example.com/current/public/index.php 

有没有一种方法来放入一个重写规则,以便我可以让服务器自动取出/ blog /目录?

就像是 ?

 location /blog { rewrite \\blog\D \; } 

你误解了root的用法。 你真正想要的是别名指令: http : //wiki.nginx.org/NginxHttpCoreModule#alias