在线求助 wordpress nginx 环境修改文章固定链接出现 404 怎么搞? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
moxian2014
V2EX    问与答

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

  •  
  •   moxian2014 2018-03-15 02:16:53 +08:00 2609 次点击
    这是一个创建于 2843 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    }

    11 条回复    2018-03-15 13:13:58 +08:00
    justinwu
        1
    justinwu  
       2018-03-15 03:37:16 +08:00 via iPhone
    睡不着,瞎答题。

    你这配置不对吧,怎么处理 php 脚本都注掉了。当然打开也是不行的,君不见只有.php 扩展名 pass 给 fast cgi 或是 apache ?文章网址搞成.html,被 nginx 默认规则匹配了,找不到就 404 了。
    需要配置 url rewrite 吧,看看 wordpress 说明文档。
    caoguo
        2
    caoguo  
       2018-03-15 05:16:00 +08:00 via Android
    第一行 #user nobody 要改成 root 或有权限的用户
    taifu
        3
    taifu  
       2018-03-15 07:51:46 +08:00 via Android
    简单点说,宝塔后来有个设置伪静态的可以选择,改成 wp 的,然后进 wp 后台把固定链接再保存一下,然后就行了。
    zyxbcde
        4
    zyxbcde  
       2018-03-15 07:55:40 +08:00 via Android
    改成数字链接,就是 id=xxx 那种,在 wordpress 设置里面,应该有更好的办法,不过这个最简单。。
    taifu
        5
    taifu  
       2018-03-15 07:57:03 +08:00 via Android
    @taifus 后来->后台
    DT27
        6
    DT27  
       2018-03-15 07:57:07 +08:00
    还是喜欢 apache 跟.htaccess 文件~
    nginx 那动不动 502 的错误还没有具体信息你们是怎么忍受的。。。
    v2ex 都动不动就 502
    DT27
        7
    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
        8
    sjwuny  
       2018-03-15 08:53:38 +08:00
    伪静态规则没设置对
    moxian2014
        9
    moxian2014  
    OP
       2018-03-15 12:00:03 +08:00
    @taifus 哈哈 感谢老哥 可以了 看来还是对宝塔不太熟啊
    moxian2014
        10
    moxian2014  
    OP
       2018-03-15 12:00:24 +08:00
    @taifus 感谢
    taifu
        11
    taifu  
       2018-03-15 13:13:58 +08:00 via Android
    @moxian2014 不客气,原来也遇到过一样的问题。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     4338 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 36ms UTC 10:03 PVG 18:03 LAX 02:03 JFK 05:03
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86