【问题标题】:wordpress nginx 404 pagewordpress nginx 404页面
【发布时间】:2018-05-10 09:59:45
【问题描述】:

我遇到了一个问题。在将当前网站从 LAMP 迁移到 LEMP 后,我遇到了 wordpress 404 页面无法正常工作的问题。配置将在下面提供。 当我试图访问不存在的页面时,我得到的是 301 而不是 404。 我读过很多关于类似问题的文章,但没有任何帮助。 我认为问题出在这一行:

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

Nginx 会检查静态文件是否存在,然后检查目录是否存在,然后才会运行 index.php。据我了解 index.php 没有运行,检查目录 Nginx 重定向到主页后。

你有什么想法吗? 我的配置(我使用 ajenti 进行服务器管理,所以配置是通过 ajenti 生成的)

#AUTOMATICALLY GENERATED - DO NO EDIT!
server {
    listen *:80;

    server_name server.com;

    access_log /var/log/nginx/servercom.access.log;
    error_log /var/log/nginx/servercom.error.log;

    root /srv/server.com;
    index index.html index.htm index.php;

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/server.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/server.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    #Redirect non-https traffic to https
    if ($scheme != "https") {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    # Global restrictions configuration file.
    # Designed to be included in any server {} block.
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
    # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
    location ~ /\. {
        deny all;
    }

    # Deny access to any files with a .php extension in the uploads directory
    # Works in sub-directory installs and also in multisite network
    # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
    location ~* /(?:uploads|files)/.*\.php$ {
        deny all;
    }


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

    error_page 404  /404.html;

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }

    #Yoast SEO Sitemaps
    location ~ ([^/]*)sitemap(.*).x(m|s)l$ {
    ## this redirects sitemap.xml to /sitemap_index.xml
    rewrite ^/sitemap.xml$ /sitemap_index.xml permanent;
    ## this makes the XML sitemaps work
    rewrite ^/([a-z]+)?-?sitemap.xsl$ /index.php?xsl=$1 last;
    rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;
    rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
    ## The following lines are optional for the premium extensions
    ## News SEO
    rewrite ^/news-sitemap.xml$ /index.php?sitemap=wpseo_news last;
    ## Local SEO
    rewrite ^/locations.kml$ /index.php?sitemap=wpseo_local_kml last;
    rewrite ^/geo-sitemap.xml$ /index.php?sitemap=wpseo_local last;
    ## Video SEO
    rewrite ^/video-sitemap.xsl$ /index.php?xsl=video last;
    }


    location ~ [^/]\.php(/|$) {
        alias /srv/webspace.by;
        fastcgi_intercept_errors on;
        fastcgi_pass php;

        fastcgi_index index.php;
        include fcgi.conf;
        fastcgi_pass unix:/var/run/ajenti-v-php7.0-fcgi-webspaceby-php7.0-fcgi-0.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

}

【问题讨论】:

    标签: wordpress nginx http-status-code-404


    【解决方案1】:

    您是否尝试将error_page 404 /404.html; 注释掉?

    【讨论】:

      猜你喜欢
      • 2017-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-04
      • 1970-01-01
      • 1970-01-01
      • 2017-02-03
      • 2015-06-10
      相关资源
      最近更新 更多