将.htaccess转换为nginx。 重写不应该如此

我无法将.htaccess转换为nginxconfiguration。 我一直在尝试使用在线转换工具。 .htaccess转换如下:

RewriteEngine on RewriteCond %{REQUEST_URI} !/public RewriteCond %{REQUEST_URI} !/index.php RewriteRule ^(.*)$ index.php/?params=$1 [NC] 

我一直在尝试使用下面的nginxconfiguration:

 location / { rewrite ^(.*)$ index.php/?params=$1; } 

这只是不正常的工作。 它也允许访问这个目录中的其他文件。 我只想要index.php可用。 甚至需要使用.htaccess规则。

在生产服务器上不能安装apache / httpd。 而且我不想浪费资源在docker中运行apache。

在Apache中,您可以使用这些RewriteCond指令来排除!/public/index.php 。 在Nginx中,只需为它们添加一个单独的location即可:

 location /public { } location = /index.php { } 

你的rewrite几乎就在那里,但是和Apache不同的是,Nginx中的replacestring总是相对于根(不是相对location ),并且应该具有前导/ 。 另外,我build议删除之间的斜线php/? 因为不必要。

 location / { rewrite ^(.*)$ /index.php?params=$1; }