首先config.php中URL_MODEL = 2
VHOST loaction / {
添加 try_files $ uri $ uri / /index.php?s=$uri&$args;
}
意思是:如果第一个$ URI不存在,就访问$ URI /;如果$ URI /还不存在,访问/index.php?s=$uri&$args可以后面跟很多个。
try_files从字面上理解就是尝试文件,再结合环境理解就是“尝试读取文件”,那他想读取什么文件呢, 答:读取静态文件
$ uri这个是nginx的一个变量,存放着用户访问的地址, 比如:http://www.xxx.com/index.html,那么$ uri就是/index.html
$ uri /代表访问的是一个目录,比如:http://www.xxx.com/hello/test/,那么$ uri /就是/ hello / test /
完整的解释就是:try_files去尝试到网站目录读取用户访问的文件,如果第一个变量存在,就直接返回; 不存在继续读取第二个变量,如果存在,直接返回;不存在直接跳转到第三个参数上。 |
再例如:
1 |
|
什么意思呢?URI不能成功访问,那好,那就给你个404吧。
服务器{
listen 80;
server_name www.search.com;
root“F:\ PHPTutorial \ WWW \ CRM-Search \ Public”;
location / {
try_files $ uri $ uri / /index.php?s=$uri&$args;
index index.php;
#autoindex on;
}
location~ \ .php(。*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U)。+ \ .php)(/?。+)$;
fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
fastcgi_param PATH_INFO $ fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $ document_root $ fastcgi_path_info;
包括fastcgi_params;
}
}
加这个 也 可以的
if (!-e $request_filename)
{
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
server {
listen 80;
server_name www.rights.com ;
root "F:\PHPTutorial\WWW\api_rights\public";
index index.php index.html index.htm;
sendfile off;
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}server {
listen 80;
server_name www.rights.com ;
root "F:\PHPTutorial\WWW\api_rights\public";
index index.php index.html index.htm;
sendfile off;
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}