【发布时间】:2020-06-03 21:24:04
【问题描述】:
我正在尝试将 CodeIgniter 下的站点从 Apache 迁移到 Nginx。我的第一次测试显示了非常好的性能,所以这次尝试最糟糕。
但我找不到正确的 Nginx 配置来替换那些 RewriteRules :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
我在 Nginx 网站https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/找到了这个食谱
location / {
try_files $uri $uri/ /index.php;
}
它在大多数情况下都有效,除非我有一个斜杠。意义 http://example.com/controller/param/
将调用http://example.com/controller/function/index.php(并返回 404)
而不是 http://example.com/index.php/controller/function/ ...因为它通常使用 Apache 重写。
我尝试添加重写:
rewrite ^/(.*)/$ /$1 permanent;
但它会将 POST 重定向到 GET,所以我丢失了所有的帖子数据...
有什么线索吗?
谢谢
【问题讨论】:
标签: codeigniter nginx-location