URL重写规则在nginx上不起作用

URL重写规则在nginx上不起作用,nginx,rewrite,Nginx,Rewrite,我想在nginx中进行类似apache的url重写。基本上是给基于位置的请求一个更加url友好的外观。我一直找不到404页 server { # site definitions (...) # fastcgi defitions (...) location / { # Code to make wp super cache work (...) rewrite ^/ads/category/(.*)/(.*)$ /ads/category/$1?loca

我想在nginx中进行类似apache的url重写。基本上是给基于位置的请求一个更加url友好的外观。我一直找不到404页

server {

  # site definitions (...)

  # fastcgi defitions (...)

  location / {

    # Code to make wp super cache work (...)

    rewrite ^/ads/category/(.*)/(.*)$ /ads/category/$1?location=$2 permanent;
    rewrite ^/category/(.*)/(.*)$ /ads/category/$1?location=$2 last;
    rewrite ^/category/(.*)$ /ads/category/$1 last;

  }
}

我将上述代码放在虚拟主机定义/etc/nginx/sites enable/mysite中。到目前为止,我还不知道一个真正的方法来调试正在发生的事情。

而不是在单个位置/{}块中定义所有重写规则;试着这样做:

# site definitions (...)

location / {
    # Code to make wp super cache work (...)

    # remove following line if you already have an index at site definitions..
    index index.php;

    try_files $uri $uri/ /index.php?$args;
  }

  if (!-f $request_filename) {
       rewrite ^/ads/category/(.*)/(.*)$ /ads/category/$1?location=$2 permanent;
       rewrite ^/category/(.*)/(.*)$ /ads/category/$1?location=$2 break;
       rewrite ^/category/(.*)$ /ads/category/$1 break;
  }

 # fastcgi defitions (...)
我知道在nginx世界中,但在location{}block中使用时会出现问题,在我的虚拟服务器上,类似的配置工作起来就像一个符咒