【问题标题】:Wordpress nginx preview post is 404 not found, but old posts are workingWordpress nginx 预览帖子是 404 未找到,但旧帖子正在工作
【发布时间】:2013-06-21 09:38:39
【问题描述】:

我最近将我的 wordpress 网站从一个主机移到了另一个主机。以前我使用 Apache 运行 wordpress,但后来按照本教程 How to Install Wordpress with nginx on Ubuntu 12.04 配置了 nginx

一切正常,但是当我尝试从管理面板预览新帖子时,它显示未找到错误。但是所有已经发布的帖子都运行良好。

当我点击预览帖子时,它向我显示网址,例如 http://mydomain.com/?p=2671&preview=true但是页面是404。

页面标题Nothing found for ?p=2671&preview=true

我的nginx配置是:

server {
    listen    127.0.0.1:8080;
    #listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default ipv6only=on; ## listen for ipv6

    root /usr/share/nginx/www/mysite/public;
    index index.php index.html index.htm;

    server_name mydomain.com;   

    location / {
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        deny all;
    }

    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 /usr/share/nginx/www;
    }       

    location ~ \.php$ {
                #fastcgi_pass 127.0.0.1:9000;
                # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;

    }   
}

我还安装了 All In One SEO Pack 插件,并从我的管理员那里启用了此格式的永久链接 /%year%/%monthnum%/%postname%/

我搜索了很多论坛,但仍然找不到确切的解决方案。请帮我解决这个问题。

谢谢

【问题讨论】:

    标签: wordpress nginx varnish permalinks


    【解决方案1】:

    终于找到答案了。 Varnish 配置的问题,不允许创建 cookie。

    打开清漆配置。在我的情况下,文件位于 /etc/varnish/default.vcl 并添加以下行

    # Drop any cookies sent to Wordpress.
    sub vcl_recv {
            # Allow posts preview 
            if (req.url ~ "preview=true") { 
                    return(pass); 
            }
            if (!(req.url ~ "wp-(login|admin)")) {
                    unset req.http.cookie;
            }
    }
    

    然后重启 nginx 和 varnish

    sudo service nginx restart
    
    sudo service varnish restart
    

    【讨论】:

      【解决方案2】:

      我已尝试在 Ubuntu 12.04+nginx+php-fpm 上重现您的问题,但没有效果。这意味着预览按预期工作。唯一的区别是我取消了 fast_cgi_pass 127.0.0.1:9000 行的注释并注释掉了另一行。正如我所见,您已在标签中添加了“清漆”,因此此处建议的清漆可能有问题-> http://wordpress.org/support/topic/nginx-cant-preview-posts-404-error

      【讨论】:

        【解决方案3】:

        我的 wordpress 服务器只需要 2 个块

        location / {
            try_files $uri /index.php$request_uri;
        }
        location ~ \.php {
            include fastcgi_params;
            fastcgi_pass   unix:/var/run/php5-fpm.sock; # replaced this with ur sock location
        }
        

        我不知道 SEO 插件,我使用的是不同的。

        【讨论】:

          【解决方案4】:

          改变:

          location / {
              try_files $uri $uri/ /index.php?q=$uri&$args;
          }
          

          到:

          location / {
              try_files $uri $uri/ /index.php?$args;
          }
          

          【讨论】:

            猜你喜欢
            • 2013-08-21
            • 2023-04-06
            • 1970-01-01
            • 1970-01-01
            • 2015-06-06
            • 2014-12-08
            • 1970-01-01
            • 2015-11-10
            • 1970-01-01
            相关资源
            最近更新 更多