Nginx404 page processing and pathInfo and hide index. php summary today's development company official website: http://www.zstime.com/. if you have a question, how can you set pathinfoin under nginxto hide index.php?
Here we will explain it separately:
1. hide index. php
To hide index. php, you need to modify the nginx configuration file. if you use vhost, you need to modify it, for example, conf/vhost/your file name. conf.
File, the entire file is as follows
server { listen 80; server_name www.zstime.com; index index index.html index.htm index.php; root /alidata/www/ZStimeBro/; error_page 404 /error.html; location / { if (!-e $request_filename){ rewrite ^/(.*)$ /index.php/$1 last; } } location ~ \.php($|/) { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~.*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~.*\.(js/css)?$ { expires 1h; } #α??????? include /alidata/server/nginx/conf/rewrite/default.conf; access_log /alidata/log/nginx/access/default.log;}
Added:
location / { if (!-e $request_filename){ rewrite ^/(.*)$ /index.php/$1 last; } }
Redirects the request link and adds index. php to remove index. php.
2. support for adding pathInfo
Nginx does not support pathInfo. we need to parse the URL by ourselves
location ~ \.php($|/) { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
Note: There are more than one method to add pathInfo, but this method is relatively simple.
Where
~ \.php($|/)
Is the url that matches the request path containing. php.
3. add 404
The addition of the 404 page has been difficult for a day. you must first enable it in nginx. conf.
fastcgi_intercept_errors on;
You must enable this option. Otherwise, you cannot customize the 404 page.
Then modify the configuration file corresponding to the vhost and add:
error_page 404 /error.html;
Remember not to add "=.
In theory, this is the end, but the browser tried to find that it still does not work. is the status always displayed 200! One day is spent here !! After checking for a long time, I found that it was not a problem with the configuration file, but a problem with the framework I used. when I used broPHP, this small framework didn't actually handle page 404. okay, please refer to http://www.csdn123.com/html/exception/693/693838_693845_693847.htm!
Summary: sometimes, you may think that the problem is safe, and that you think is safe is often a problem!