在nginx中重写规则

我正在使用php-fpm将Apache应用程序从Apache移动到Nginx。 我差不多完成了,除了一个我在Nginx中没有做的重写指令。 以下是我需要端口的Apacheconfiguration的摘录:

# Handle alianza.quehambre.cl RewriteCond %{HTTP_HOST} ^alianza\.quehambre\.cl [NC] RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-l RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !(api|get)/(.*) RewriteRule ^(.*)$ /index.php/get/$1 [L,QSA] 

完整的Nginxconfiguration在这个要点 ,包括我目前的非工作尝试写出上述规则。

这应该做的伎俩:

 server { server_name alianza.quehambre.cl; location / { location ~ ^/(api|get)/(.*) { # Whatever should happen at this point... } try_files $uri /index.php/get/$request_uri =404; } } 

试试这个:

  location ~ (api|get)/(.*) { } location / { if ($http_host ~* "^alianza\.quehambre\.cl"){ rewrite ^(.*)$ /index.php/get/$1 break; } }