V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
moxian2014
V2EX  ›  问与答

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

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

    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 或有权限的用户
    taifus
        3
    taifus  
       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 设置里面,应该有更好的办法,不过这个最简单。。
    taifus
        5
    taifus  
       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 感谢
    taifus
        11
    taifus  
       2018-03-15 13:13:58 +08:00 via Android
    @moxian2014 不客气,原来也遇到过一样的问题。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5749 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 06:09 · PVG 14:09 · LAX 23:09 · JFK 02:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.