try_files $uri $uri/ /index.php$is_args$args;
Put this line of code in the server {} block.
Explanations:
The first is the nginx try_files command. When a request occurs, such as "/ABC", it will check "/ABC" ($ URI) whether the file exists and whether the "/ABC/" ($ uri/) directory exists. If not, redirect to the last parameter "/index. PHP $ is_args $ ARGs ".
We know that index. php is the "entry file" of the framework ".
$ ARGs is a built-in nginx variable that represents the query string in the URL, that is, the get parameter, like "A = 1 & B = 2 & C = 3 ".
$ Is_args depends on $ ARGs, which is expressed in a single expression of three elements: $ is_args = empty ($ ARGs )? '':'? ';
In this way, let's assume several URLs to see how the redirection works:
/Index/Index =>/index. php
/Admin/index? Id = 1 =>/index. php? Id = 1
Is it strange that, after the redirection, the paths disappear, so how can we route the routes inside the framework?
The answer is $ _ server ['request _ URI '] (this is not the only way. The framework will also consider the special processing in path_info and IIS, but nginx and Apache only need to have request_uri.) You only need to know that, although nginx has been internally redirected, The request_uri parameter is not changed, which indicates the original URL, that is, the URL in the address bar of the browser.
After the above two redirection occurs, in fact:
$ _ Server ['request _ URI '] = "/index/Index ";
$ _ Server ['request _ URI '] = "/admin/index? Id = 1 ";
Then, the framework will parse the route according to $ _ server ['request _ URI.
I have attached my own Configuration:
Server {Listen 80; SERVER_NAME your own domain name; index index.html index.htm index. PHP; root/home/wwwroot/yaf; try_files $ URI // index. PHP $ is_args $ ARGs; location ~ . * \. (PhP | PhP5 )? $ {Fastcgi_pass Unix:/tmp/php-cgi.sock; fastcgi_index index. php; Include fcgi. conf;} location/status {stub_status on; access_log off;} location ~ . * \. (GIF | JPG | JPEG | PNG | BMP | SWF) $ {expires 30d;} location ~ . * \. (JS | CSS )? $ {Expires 12 h;} access_log/home/wwwlogs/access. Log Access ;}