在线求助 wordpress nginx 环境修改文章固定链接出现 404 怎么搞?

2018-03-15 02:16:53 +08:00
 moxian2014

wordpress 后台固定链接自定义为 /%post_id%.html,然后发布文章都是 404···有点崩溃。服务器是 centos 系统,用的宝塔面板,搜索了好多解决方法没找到合适的,毕竟是菜鸟~ nginx 配置文档贴出来大神们来看看··· #user nobody; worker_processes 1;

#error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info;

#pid logs/nginx.pid;

events { worker_connections 1024; }

http { include mime.types; default_type application/octet-stream;

#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
#                  '$status $body_bytes_sent "$http_referer" '
#                  '"$http_user_agent" "$http_x_forwarded_for"';

#access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   html;
        index  index.html index.htm;
    }

    #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;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;
#    listen       somename:8080;
#    server_name  somename  alias  another.alias;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}


# HTTPS server
#
#server {
#    listen       443 ssl;
#    server_name  localhost;

#    ssl_certificate      cert.pem;
#    ssl_certificate_key  cert.key;

#    ssl_session_cache    shared:SSL:1m;
#    ssl_session_timeout  5m;

#    ssl_ciphers  HIGH:!aNULL:!MD5;
#    ssl_prefer_server_ciphers  on;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}

}

2016 次点击
所在节点    问与答
11 条回复
justinwu
2018-03-15 03:37:16 +08:00
睡不着,瞎答题。

你这配置不对吧,怎么处理 php 脚本都注掉了。当然打开也是不行的,君不见只有.php 扩展名 pass 给 fast cgi 或是 apache ?文章网址搞成.html,被 nginx 默认规则匹配了,找不到就 404 了。
需要配置 url rewrite 吧,看看 wordpress 说明文档。
caoguo
2018-03-15 05:16:00 +08:00
第一行 #user nobody 要改成 root 或有权限的用户
taifus
2018-03-15 07:51:46 +08:00
简单点说,宝塔后来有个设置伪静态的可以选择,改成 wp 的,然后进 wp 后台把固定链接再保存一下,然后就行了。
zyxbcde
2018-03-15 07:55:40 +08:00
改成数字链接,就是 id=xxx 那种,在 wordpress 设置里面,应该有更好的办法,不过这个最简单。。
taifus
2018-03-15 07:57:03 +08:00
@taifus 后来->后台
DT27
2018-03-15 07:57:07 +08:00
还是喜欢 apache 跟.htaccess 文件~
nginx 那动不动 502 的错误还没有具体信息你们是怎么忍受的。。。
v2ex 都动不动就 502···
DT27
2018-03-15 08:04:29 +08:00
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
上面是伪静态的规则。
下面是 php 解析的,具体配置你自己试试。
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
sjwuny
2018-03-15 08:53:38 +08:00
伪静态规则没设置对
moxian2014
2018-03-15 12:00:03 +08:00
@taifus 哈哈 感谢老哥 可以了 看来还是对宝塔不太熟啊
moxian2014
2018-03-15 12:00:24 +08:00
@taifus 感谢
taifus
2018-03-15 13:13:58 +08:00
@moxian2014 不客气,原来也遇到过一样的问题。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/438155

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX