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 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;
access_ log  logs/ combined;
root /home/wwwroot/;
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;
location ~ \.php {
fastcgi_ pass;
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 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, this can basically be achieved Pathinfo path From my personal use, if we just need to build a website, or don't 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.

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

Scan the code to follow the official account

Get more news about webmaster circle!
Entrepreneurship, operation and new knowledge