启用永久链接和无扩展php路由在Nginx中不起作用

启用永久链接和无扩展php路由在Nginx中不起作用,php,wordpress,nginx,permalinks,Php,Wordpress,Nginx,Permalinks,我的nginx.conf文件如下: server { ... root /var/www/html; # Add index.php to the list if you are using PHP index index.php index.html index.htm index.nginx-debian.html; server_name mydomain.com; if

我的
nginx.conf
文件如下:

server {
    ...    
root /var/www/html;

            # Add index.php to the list if you are using PHP
            index index.php index.html index.htm index.nginx-debian.html;

            server_name mydomain.com;

            if (!-e $request_filename)
            {
             rewrite ^.*$ /index.php last;
            }


            location / {

                    try_files $uri $uri/ @extensionless-php;
            }


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

            location @extensionless-php {
                    rewrite ^(.*)$ $1.php last;
            }
}
我已经在运行Ubuntu服务器的Nginx上安装了WordPress

我有一个名为Resume的导航菜单,它指向并显示一个pdf文件,实际上是myname\u Resume.pdf,但我已将Resume.php放在根目录中,此php脚本获取myname\u Resume.pdf的内容,并将其显示为pdf文件

我希望我的url永远不要附加任何文件扩展名.pdf.php,无论您是否有人可以编写url.php,它都会给出相同的结果,因此我已经这样做了。当我输入以下代码时,
extensionless php
的配置运行良好:

if (!-e $request_filename)
{
    rewrite ^.*$ /index.php last;
}

由于我已经安装了WordPress,我想给WordPress上创建的页面提供permalink,为了启用permalink,我不得不添加上面的小配置。现在permalink正在打开,但是mydomain.com/resume给出了404错误。如何实现这两个目标,或者有什么好方法可以实现这一目标

而不是将
.php
附加到任何不存在的文件中-您可以更改逻辑,使
.php
仅在php文件实际存在时附加到URI中

例如:

location / {
    try_files $uri $uri/ @rewrite;
}
location @rewrite {
    if (-f $request_filename.php) {
        rewrite ^ $uri.php last;
    }
    rewrite ^ /index.php last;
}
location ~ \.php$ {
    try_files $uri =404;
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
请参见关于
的使用,如果