如何使用nginx配置pathinfo模式?
使用nginx隐藏thinkphp的index.php入口文件。配置的目的主要是为了美化路由,让路由更好看,比如:
//不隐藏index.php
http://localhost:8000/index.php/api/server/lists
//隐藏index.php
http://localhost:8000/api/server/lists
配置pathinfo之后,上面两种方法都可以使用。不配置pathinfo的话,不能隐藏index.php入口文件。
server {
listen 80;
server_name _;
root /var/www/html/tp5/public;
index index.php index.html index.htm;
location / {
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
}
server {
listen 80;
server_name _;
root /var/www/html/tp5/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$uri$is_args$args;
}
}
只需要选择一种进行配置即可。配置完之后,记得重启nginx才会生效。