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

Typecho Nginx environment root directory and subdirectory pseudo static rule file

Generally, we will install the website program in the root directory of the site, so that when we use the pseudo static rules, we can directly call the default configuration file. However, sometimes we need to install the website program to the secondary directory (an independent folder under the root directory), so that we can achieve the effect of a secondary directory/subdirectory independent channel site.

Among them, Lao Zuo shared it in his early days“ Resolve the pseudo static problem of the LNMP (Nginx) secondary directory wordpress website "Today, we encountered the need to install Typecho programs in subdirectories. Here we share two possible pseudo static rules under Typecho Nginx system as follows.

First, root directory Typecho rules

location / {
index index.html index.php;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}

Second, subdirectory pseudo static rules

Location/subdirectory folder/{
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php last;
}
if (!-f $request_filename){
Rewrite (. *)/subdirectory folder/index.php last;
}
}

If we have two TYPEHO or other programs in the same site, whoever is in the subdirectory will throw the rules of the subdirectory into the configuration file. Note that the name of the subdirectory folder needs to be modified.

Finally, restart Nginx to check whether an error is reported. If no error is reported, there should be no problem.

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 » Typecho Nginx environment root directory and subdirectory pseudo static rule file


Scan the code to follow the official account

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