Wordpress 类别链接在 Nginx 服务器上不起作用

Wordpress 类别链接在 Nginx 服务器上不起作用

我刚刚配置了一台新服务器来迁移我的网站。迁移后,除了类别链接之外,一切都正常。如果我们访问某个类别,它会给出 404 错误。页面永久链接工作正常!可能是什么问题?

nginx 配置:

server {
        listen   80;


        root /var/www/androidgadgematic;
        index index.php index.html index.htm;

        server_name androidgadgematic.com www.androidgadgematic.com;

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

        location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
            expires 10d;
        }

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;

        location = /50x.html {
              root /usr/share/nginx/www;
       }


        location ~ /\. {
                deny all;
                access_log off;
                log_not_found off;
        }

        location ~ /nginx.conf {
                deny all;
                log_not_found off;
                access_log off;
        }

        location ~ ^/feed/(.+)\.html$ {
                if ($args != '') {
                rewrite ^(.*) $1? permanent;
                }
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
        }

        include /var/www/androidgadgematic/nginx.conf;
        location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; }
        location ~ "^/ngx_pagespeed_static/" { }
        location ~ "^/ngx_pagespeed_beacon$" { }
        location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all; }
        location /ngx_pagespeed_global_statistics { allow 127.0.0.1; deny all; }
        location /ngx_pagespeed_message { allow 127.0.0.1; deny all; }
        location /pagespeed_console { allow 127.0.0.1; deny all; }

        location ^~ /wp-login.php {
                auth_basic            "Restricted Area: WordPress";
                auth_basic_user_file  /var/www/.htpasswd;
                try_files $uri =404;
                #fastcgi_pass 127.0.0.1:9000;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
        }

}

PS:甚至 wp-admin 也给出 404

fastcgi.conf:

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

附言:我从源代码下载并编译了 Nginx 来安装 Page Speed。这可能是问题所在吗?

答案1

将其移至底部:

location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi.conf;
    }

并添加

  fastcgi_index index.php;
  fastcgi_split_path_info ^(.+\.php)(.*)$;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

在 try_files 指令下

相关内容