Focus on cloud service provider activities
Notes on website operation and maintenance

Configure Nginx environment to support pathinfo mode path function method

Due to the particularity of the requirements, many of our CMS programs or specific environments need to support pathinfo mode path functions. For example, in the morning, a Typecho CMS program used by a netizen needs to support similar functions in pseudo static paths https://www.laozuo.org/index.php/article_info/id/10 This format effect. The pathinfo mode is not supported in the default Nginx configuration environment. We need to set the startup mode.

First, AMH panel environment

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

 AMH Panel Environment

If you use the AMH panel, it is relatively simple. It takes effect when you activate it directly with a component, and no configuration file is required.

Second, configure the Pathinfo function in the LNMP environment

If we use one button package, Lao Zuo is right here linuxeye Start the Pathinfo function in the LNMP environment of the provided one click package.

1. Configure the website. conf file

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  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;
include fcgi_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 where we need to set pathinfo function, and then modify it accordingly.

2. Modify the fcgi_pathinfo.conf file

#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;

The 2 lines marked in red need to be # commented out.

To sum up, we can basically achieve the pathinfo path effect. From my personal use, if we just need to build a simple website, we should not use this path. The user experience and search experience are very poor. It is better to use ordinary pseudo static or generate static. Unless our special website environment needs, we have no way to use it.

Vote for you
Domain name host preferential information push QQ group: six hundred and twenty-seven million seven hundred and seventy-five thousand four hundred and seventy-seven Get preferential promotion from merchants.
Like( zero )
Do not reprint without permission: Lao Zuo's Notes » Configure Nginx environment to support pathinfo mode path function method