欢迎光临
我们一直在努力

WordPress在Nginx环境下配置伪静态

最近服务器流量暴增,服务器的Apache进程出现进程不断增长而出现进程不能及时杀死释放内存的问题,由pre-fork模式更改为worker模式也不能起到明显效果。
最后只能将Wordpress博客整体由LAMP切换到LEMP环境,访问正常后,发现Nginx环境下的伪静态设置与Apache的.htaccess设置方式略有不同,在此记录一下。

Apache环境下使用.htaccess实现Wordpress的通用伪静态效果

RewriteEngine On

RewriteBase /

RewriteRule ^index.php$ – [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

 

Nginx环境下需要做如下重写,适用于wordpress

location / {
         try_files $uri $uri/ /index.php?$args;
}

location / {
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;
}
}
————————————————
配置完成后,重启Nginx

然后,在wordpress博客后台的“设置”——“固定链接”,自定义结构(我的设置为:/%category%/%post_id%.html   即:分类/文章id.html)

至此,wordpress博客伪静态设置完成。

WordPress在Nginx环境下配置伪静态-军哥驿站

下面大致讲一下固定链接设置参数:

1. %year% 基于文章发布年份,比如2007;
2. %monthnum% 基于文章发布月份,比如05;
3. %day% 基于文章发布当日,比如28;
4. %hour% 基于文章发布小时数,比如15;
5. %minute% 基于文章发布分钟数,比如43
6. %second% 基于文章发布秒数,比如33
7. %postname% 基于文章的postname,其值为撰写时指定的缩略名,不指定缩略名时是文章标题;
8. %post_id% 基于文章post_id,比如423;
9. %category% 基于文章分类,子分类会处理成“分类/子分类”这种形式;
10. %author% 基于文章作者名。
将上述参数进行组合,即可得到wordpress的固定链接形式。网上常见的几种设置方法:
/%year%/%monthnum%/%day%/%postname%/
/%year%/%monthnum%/%postname%/
/%year%/%monthnum%/%day%/%postname%.html
/%year%/%monthnum%/%postname%.html
/%category%/%postname%.html
/%category%/%post_id%
/%postname%.html
/%post_id%.html 我们一般使用这个方式比较好。

支付宝扫码打赏 微信扫码打赏

如果文章对你有帮助,欢迎点击上方按钮打赏作者

未经允许不得转载:军哥驿站 » WordPress在Nginx环境下配置伪静态

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

军哥驿站 建站更专业 更方便

网站开发联系我们