Nginx 404 page processing and pathInfo and hide index. php summary, nginxpathinfo

Source: Internet
Author: User

Nginx 404 page processing and pathInfo and hide index. php summary, nginxpathinfo

On the official website of the development company today: 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!

Reprinted please indicate the source: Guo shenglong blog: http://blog.csdn.net/guoshenglong11/article/details/39324747 thank you!



Set the header in php to return 404, but the page blank is related to phpini/nginx.

404 not found
The webpage is not found, indicating that the webpage has been deleted or renamed on the server. Add a blacklist in the Security Assistant and enter the website address of the website. It is not allowed to pop up.

404 is an encoding of not found errors. The HTTP protocol error information may be different in different software and languages, but its code is uniform, so that the browser can correctly identify and handle the problem.
 
After nginx + php is installed, 404 is displayed when the Php page is accessed, but the page exists.

/Usr/local/nginx/html/scripts?
Changed?
Fastcgi_param SCRIPT_FILENAME/scripts $ fastcgi_script_name;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.