Nginx解决WordPress更改固定链接产生的404问题

我的网站结构是Ubuntu+Nginx+MariaDB+PHP。写了几篇文章后,发现还没有更改WordPress的固定链接。于是我将默认的固定链接形式http://www.liniuxdashen.com/?p=123 更改成 http://www.linuxdashen.com/%postname%

保存更改后,网站首页还可以访问,但是其他的页面全都是404错误。下面是解决办法,适用于Nginx网页服务器。

WordPress 404 错误的解决办法

编辑/etc/nginx/sites-available/yourwebsite 文件,在location / 这一部分当中添加下面的一行文字。

try_files $uri $uri/ /index.php;

如下图:

Nginx

 

然后重启Nginx服务器

sudo systemctl restart nginx 或 sudo service nginx restart

这个办法也可以解决其他内容管理系统比如Drupal的固定链接问题。

有时候php-fpm进程也可能会导致WordPress 404问题。如果你在Nignx的错误日志中看见下面的错误:

upstream timed out (110: Connection timed out) while reading response header from upstream, client: 108.162.215.11, server: www.linuxdashen.com, request: "GET /wp-admin/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.linuxdashen.com"

这表明fastcgi连接超时,大多数情况下我们只需要重启php-fpm进程就可以解决这个问题

sudo service php5-fpm restart    或   sudo systemctl restart php5-fpm

希望这篇文章可以帮你解决WordPress的404问题。

为这篇文章评分
[Total: 2 Average: 3]

Leave a Reply

Your email address will not be published.

The maximum upload file size: 2 MB. You can upload: image, audio, video, document, spreadsheet, interactive, text, archive, code, other. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here