banner
李大仁博客

李大仁博客

天地虽大,但有一念向善,心存良知,虽凡夫俗子,皆可为圣贤。

[Nginx] 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 / {
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;
}
}

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.