解决Nginx环境wordpress设置固定链接打开失败问题

来源:互联网 发布:知乎 极简主义生活 编辑:程序博客网 时间:2024/06/06 09:58
  • 网上有现成的解决文章为什么要重新写一篇?因为看文章并没有直接解决我的问题。参考已有文章,又折腾了会。

  • 解决了就行,为什么要再写一篇?因为我又遇到了这个问题,而且又折腾了好几分钟。

这个问题,一旦需要解决,会很烦。所以记一下。

/etc/nginx/conf.d/wordpress.conf 配置文件全文,好用。

server {    listen 80;    root /usr/share/wordpress;    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;}     rewrite /wp-admin$ $scheme://$host$uri/ permanent;     location / {        try_files $uri $uri/ /index.php?$args;     }    rewrite /wp-admin$ $scheme://$host$uri/ permanent;      # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000    location ~ .php$ {        fastcgi_pass   127.0.0.1:9000;        fastcgi_index  index.php;        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;        include        fastcgi_params;    }}

配置文件修改完成后,在命令行:

nginx -s reload

重启nginx服务。

PHP配置文件 /etc/php.ini需要处理(是不是必要步骤不确定,但做了总没错):

将下面一行代码的注释打开,前面的 ; 删除

cgi.fix_pathinfo=1

wordpress配置
自定义结构设置为:/%postname%.html/

!!!分类目录前缀一定要写

设置如下图:
这里写图片描述

至此,问题解决。