博主在搭建本地环境PHP7.0+Nginx,安装了wordpress,在固定文章连接以后,发现大量404页面,文章无法打开,无论是新编辑的文章还是之前的,都会出现404错误。那么这个问题该如何解决呢?或者说如何在ngix server解决这种问题?查阅了资料后发现。在设置了固定链之后,首先我们应该更改网站域名所对应的配置文件,比如本地phpStudy搭建环境对应的conf文件为nginx\conf目录下nginx.conf文件。我们这里要对其进行修改。
默认配置文件如下:
server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; root "C:/php/WWW"; //注意在此添加下面给出的if语句 location / { index index.html index.htm index.php l.php; autoindex on; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #}
需要添加的代码:
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; }
正文到此结束
版权声明:除非本文有注明出处,否则转载请注明本文来自 https://xwmin.com
LEAVE A REPLY