[英]Setup SlimPHP .htaccess in Nginx
I'm trying to setup my PHP application in my Raspberry Pi. 我正在尝试在Raspberry Pi中设置我的PHP应用程序。 I'm using a Nginx server to host the application.
我正在使用Nginx服务器托管应用程序。 The SlimPHP requires a .htaccess configuration to redirect all the requests to the index.php file:
SlimPHP需要.htaccess配置,以将所有请求重定向到index.php文件:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
I've converted the htaccess using the Winginx tool and edited the /etc/nginx/nginx.conf file adding the following source, but Nginx reported a configuration error: 我已经使用Winginx工具转换了htaccess,并编辑了/etc/nginx/nginx.conf文件,添加了以下源,但是Nginx报告了配置错误:
# nginx configuration
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php break;
}
}
Restarting nginx: nginx: [emerg] unknown directive "location" in /etc/nginx/nginx.conf:98 nginx: configuration file
重新启动nginx:nginx:[emerg] /etc/nginx/nginx.conf中的未知指令“位置”:98 nginx:配置文件
/etc/nginx/nginx.conf test failed
/etc/nginx/nginx.conf测试失败
How should I proceed? 我应该如何进行?
UPDATE 更新
I 've edited the nginx.conf file as recommended but the Nginx still doesn't redirecting the URL. 我已按照建议编辑了nginx.conf文件,但Nginx仍然不重定向URL。 It shows a
File not found
answer. 它显示“
File not found
答案。 Should I edit the nginx.conf file or create any other configuration file? 我应该编辑nginx.conf文件还是创建其他配置文件?
In general, you want something like this. 通常,您想要这样的东西。 You can toggle the SLIM_MODE to development as needed.
您可以根据需要将SLIM_MODE切换为开发状态。
[Edit: Oops, posted an old version, updated to remove the if.] [编辑:糟糕,发布了旧版本,已更新以删除if。]
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404; # not needed if you have cgi.fix_pathinfo=false in php.ini
include fastcgi_params;
fastcgi_param SLIM_MODE production;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.