Configure the Nginx environment to support the pathinfo mode path function

Source: Internet
Author: User
Due to the special requirements, many CMS programs or specific environments need to support the pathinfo mode path function, for example, in the morning, the Typecho CMS program used by a netizen must support the format effect similar to http://www.laozuo.org/index.php/article_info/id/10in the pseudo-static path. In the default Nginx configuration environment, the pathinfo mode is not supported. We need to set the startup mode.

 

1. AMH panel environment

 

If we use the AMH panel environment (Nginx), we also need to manually set it in the early stage. Now it is very simple, just download and activate the AMPathinfo module in the plug-in module.

 

 

If you use the AMH panel, it is relatively simple. You can activate it directly with the component without the configuration file.

 

2. Configure Pathinfo in the LNMP environment

 

If we use a one-click package, the Pathinfo function is enabled in the LNMP environment of the one-click package provided by linuxeye.

 

1. Configure the website. conf file

 

The code is as follows: Copy code

Server {
Listen 80;
Server_name www.laozuo.org laozuo.org;
Access_log logs/www.laozuo.org. log combined;
Root/home/wwwroot/www.laozuo.org;
Error_page 404/404 .html;
Index index.html index.htm index. php;
Location /{
Index. php;
If (! -E $ request_filename ){
Rewrite ^/(. *) $/index. php/$1 last;
Break;
}
}
Location ~ \. Php {
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fcinclude gi_pathinfo.conf;
Set $ real_script_name $ fastcgi_script_name;
If ($ fastcgi_script_name ~ "^ (. +? \. Php) (/. +) $ "){
Set $ real_script_name $1;
Set $ path_info $2;
}
Fastcgi_param SCRIPT_FILENAME $ document_root $ real_script_name;
Fastcgi_param SCRIPT_NAME $ real_script_name;
Fastcgi_param PATH_INFO $ path_info;
}
}

 

Refer to the site. conf file for which we need to set the pathinfo function and modify it accordingly.

 

2. Modify the fcgi_pathinfo.conf file.

 

The code is as follows: Copy code

# Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
# Fastcgi_param SCRIPT_NAME $ fastcgi_script_name;
Fastcgi_param QUERY_STRING $ query_string;
Fastcgi_param REQUEST_METHOD $ request_method;
Fastcgi_param CONTENT_TYPE $ content_type;
Fastcgi_param CONTENT_LENGTH $ content_length;

Fastcgi_param REQUEST_URI $ request_uri;
Fastcgi_param DOCUMENT_URI $ document_uri;
Fastcgi_param DOCUMENT_ROOT $ document_root;
Fastcgi_param SERVER_PROTOCOL $ server_protocol;
Fastcgi_param HTTPS $ https if_not_empty;

Fastcgi_param GATEWAY_INTERFACE CGI/1.1;
Fastcgi_param SERVER_SOFTWARE nginx/$ nginx_version;

Fastcgi_param REMOTE_ADDR $ remote_addr;
Fastcgi_param REMOTE_PORT $ remote_port;
Fastcgi_param SERVER_ADDR $ server_addr;
Fastcgi_param SERVER_PORT $ server_port;
Fastcgi_param SERVER_NAME $ server_name;

# PHP only, required if PHP was built with -- enable-force-cgi-redirect
Fastcgi_param REDIRECT_STATUS 200;

 

Note out the two lines marked in red.

 

To sum up, we can basically achieve the pathinfo path effect. From my personal usage, if we only need to build a simple site, we still do not need to use this path, the user experience and search experience are poor. It is better to use common pseudo-static or generate static data. Unless we have special website environment requirements, we cannot use them.

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.