Php 更改永久链接后,nginx日志中的Wordpress 404

Php 更改永久链接后,nginx日志中的Wordpress 404,php,wordpress,nginx,Php,Wordpress,Nginx,因此,我在/usr/share/nginx/html中设置了登录页,在/usr/share/nginx/blog中设置了博客 正如您在下面的配置中所看到的,博客被配置为别名。每当有人试图访问博客,例如:you.com/blog,他们就会访问you.com/blog/。还是没什么好担心的。因此,在wordpress中,URL设置为普通。到目前为止一切正常,没有任何问题。现在,由于Asthics,URL需要看起来更好,即:post name。例如:you.com/blog/name of my po

因此,我在/usr/share/nginx/html中设置了登录页,在/usr/share/nginx/blog中设置了博客

正如您在下面的配置中所看到的,博客被配置为别名。每当有人试图访问博客,例如:you.com/blog,他们就会访问you.com/blog/。还是没什么好担心的。因此,在wordpress中,URL设置为普通。到目前为止一切正常,没有任何问题。现在,由于Asthics,URL需要看起来更好,即:post name。例如:you.com/blog/name of my post。如果wordpress中的配置从普通名称更改为post名称,nginx将给出一个404,并显示以下消息

2017/05/03 09:28:00 [error] 2869#0: *1492652 "/usr/share/nginx/blog/my-post/index.html" is not found (2: No such file or directory), client: 73.1.2.24, server: you.com, request: "GET /blog/my-post/ HTTP/1.1", host: "you.com", referrer: "https://you.com/blog/"
我注意到index.html在末尾被附加了。在尝试了php/blog块中的不同更改之后,我仍然坚持使用404。这是我们正在运行的配置

server {
    root /usr/share/nginx/html;
    listen 443 ssl;
    ssl_protocols TLSv1.1 TLSv1.2 ;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;
    ssl_certificate /var/keys/api_ssl.crt;
    ssl_certificate_key /var/keys/api_priv.key;
    server_name you.com;

    index index.html index.php index.htm;

    location / {
    try_files $uri $uri.html $uri/ uri.html = 404;
        }   

    location /blog {
        alias /usr/share/nginx/blog;
        if (!-e $request_filename) {
           rewrite /blog/wp-admin$ $scheme://$host$uri/ permanent;
           rewrite ^(/[^/]+)?(/wp-.*) $2 last;
           rewrite ^(/[^/]+)?(/.*\.php) $2 last;
        }   
        try_files $uri $uri/ /index.php?$args;
        location ~ \.php {
            fastcgi_pass 127.0.0.1:9000;
            include fastcgi_params;
            fastcgi_index index.php;
            $document_root/$fastcgi_script_name;
        }
    }
}
我如何在这里获得/blog/my post而不是普通类型的you.com/blog/?p=10

注:博客(/usr/share/nginx/Blog)和网站(/usr/share/nginx/html普通html)位于两个单独的文件夹中。您应该不能在/blog块之外执行任何php

编辑2017-5-04

修改的nginx.config已成功重定向到博客/帖子名

server {
    root /usr/share/nginx/html;
    listen 443 ssl;
    ssl_protocols TLSv1.1 TLSv1.2 ;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;
    ssl_certificate /var/keys/api_ssl.crt;
    ssl_certificate_key /var/keys/api_priv.key;
    server_name xyz.com;

    index index.html index.php index.htm;

    location / {
    try_files $uri $uri.html $uri/ uri.html = 404;
    }   


    location /blog {
    alias /usr/share/nginx/blog;
    index index.html index.php;
    try_files $uri $uri/ @blog;
    expires 30d;
    if ($uri ~ "^/index.php") {
        rewrite /  redirect;
    }

    location ~ \.php {
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
        fastcgi_index index.php;
    }
}

location @blog {
    rewrite ^/blog/(.*) /blog/index.php?$args;
}

您的站点似乎有明确的权限重写模块问题,因此无法重写。htaccess文件。请与您的主机提供商联系,并要求您为他们正在使用的Apache服务器重写模块。并请求授予根文件夹的写入权限,以便wordpress可以在更改永久链接时创建。htaccess文件


希望能有帮助

如果您保存了永久链接以便在url中显示文章标题,则应使用以下代码:

location / {
    try_files $uri $uri.html $uri/ uri.html = 404;
 }  
不是这样的:

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

您不需要手动设置/blog,如果您在nginx配置中具有上述功能,wordpress将为您完成此操作。如果您愿意,我可以上传我的整个配置。

您的nginx配置似乎有误。 1) 从博客中走出你的街区
location~\.php{fastcgi\u pass 127.0.0.1:9000;包括fastcgi\u参数;fastcgi\u index index.php;$document\u root/$fastcgi\u script\u name;
}
并用下面的代码替换块。
location/blog{index index.html index.php;try_files$uri$uri/@blog;过期30d;if($uri~“^/index.php”){rewrite/redirect;}}location@blog{rewrite^/blog/(.*)/blog/index.php?$args;
}

这将有助于

他使用的是nginx,而不是apache。因此我在回答中提到了这一点,希望他/她能看到这一点。在你给任何人做阴性标记之前,请仔细阅读。我很好地阅读了你的“解决方案”。你是说他应该从nginx换成apache。这不是一个解决办法。我想你也没有读过我的评论…你需要在写任何东西之前更加小心。。。作为本网站的一部分,您应该能够理解这一点。请标记我要求他将Nginx更改为Apache的部分…我将在这里急切地等待。您是说他应该向其托管提供商请求Apache的重写模块,并且他应该修复Nginx甚至不使用的.htaccess文件的权限..location/与您发布的内容相同,位置/博客有第二个。如果您正在运行相同类型的环境(博客位于与html不同的文件夹中),那么您可以发布nginx配置文件,这将非常好。nginx/html文件夹是您的非wordpress网站吗?nginx/blog是wordpress安装的根目录吗?正确。wordpress使用php,而网站(登录页)不使用php。如果你遇到css和js错误,或者像静态内容这样的图像,它就是纯html.sitll。位置~*\(?:ico | js | css | gif | jpe | g | png | gz | svg | svg | ttf | otf | woff | eot | mp4 | ogg | ogv | webm | tsv${根目录根目录;过期365d;添加头访问控制允许源“*“添加u头Pragma public;添加u缓存头控制”it},我将php保存在/blog块中,因为我不希望使用任何php脚本创建非/blog URL。一切正常&更新了上面的nginx配置文件并将您的解决方案标记为答案。干杯