nginx无法为wordpress处理php

nginx无法为wordpress处理php,php,wordpress,nginx,Php,Wordpress,Nginx,我在say myapp.com上运行了一个rails应用程序。我试图在myapp.com/blog上加载wordpress。我从一个nginx配置开始,如下所示: server { passenger_enabled on; passenger_app_env staging; server_name myapp.com; root /home/deploy/myapp/current/public; location /blog { passenger_en

我在say myapp.com上运行了一个rails应用程序。我试图在myapp.com/blog上加载wordpress。我从一个nginx配置开始,如下所示:

server {

  passenger_enabled on;
  passenger_app_env staging;

  server_name myapp.com;

  root /home/deploy/myapp/current/public;

  location /blog {
    passenger_enabled off;
    root /home/deploy/myapp/current/public;
    index index.php index.html index.htm;
  }

  location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
   }
}
在我想到将wordpress目录博客从/public/移动到/home/deploy/wordpress/blog之前,这一切都很顺利

要做到这一点,我的配置是这样的

server{
  location ^~ /blog{
    root /home/deploy/wordpress;
    passenger_enabled off;
  }

  location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
  }

  location / {
    passenger_enabled on;
    root root /home/deploy/myapp/current/public;
    passenger_app_env staging;
  }
}

此后,nginx不再执行php,而是开始下载php。有人能建议或指出我可能出错的地方吗?

删除^~操作符,它就会工作。这是因为它告诉nginx,以下位置块前缀必须优先于regex位置块,因此php在位置块选择期间尤其优先,它尝试从那里作为静态文件提供php文件,并将其作为应用程序/八位字节流传递,因为mime类型可能未知。

您的答案帮我找到了解决办法。