nginx try_files下载php文件而不是加载它

nginx try_files下载php文件而不是加载它,php,nginx,Php,Nginx,我正在尝试设置我的nginx服务器,以完成以下任务 x.com opens index.php in / x.com/example opens example.php in / x.com/example/ opens example.php in / x.com/foo/example opens example.php in /foo/ 我有以下配置 server { listen www.delibr.com:443 default_server; # if this is n

我正在尝试设置我的nginx服务器,以完成以下任务

x.com opens index.php in /

x.com/example opens example.php in /

x.com/example/ opens example.php in /

x.com/foo/example opens example.php in /foo/
我有以下配置

server {
listen www.delibr.com:443 default_server;  # if this is not a default server, remove "default_server"
root /var/delibr.se;
index index.php index.html index.htm; # this is also irrelevant

server_name www.delibr.com;
ssl_certificate /path to/crt;
ssl_certificate_key /path to/key;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;

location /beta {
    return 302 /#signup-form;
}

location / {
   try_files $uri $uri.php $uri/;
    if ($host != 'www.delibr.com') {
        rewrite     ^ https://www.delibr.com$request_uri? permanent;
    }
}

location ~ [^/]\.php(/|$) {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

    # With php5-fpm:
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    }

}

通过此设置/example下载example.php和/example/给出500个内部服务器错误。有人能帮我吗?

您的
文件应该如下所示

try_files $uri $uri/ $uri.php;
除最后一个参数外,所有参数都在当前上下文中测试。因此,当您使用
$uri.php
并找到该文件时,当前上下文将作为一个静态文件使用,它确实是这样做的。但对于最后一个参数,它将对照配置中的其他位置块进行检查

编辑-1

您对/
中的
x.com/example/opens example.php的请求不是常见的请求,要使其正常工作有点困难。当我们在
try_files
中有
$uri.php
时,它会将url更改为
x.com/example/.php
。因此,我们需要通过添加一个额外的块来处理这个url

location ~* /\.php {
   rewrite ^(.*)/\.php$ $1.php redirect;
}

谢谢几乎成功了。但是它没有解决
x.com/example/在/
中打开example.php,它会生成“未指定输入文件”。是的,这很明显,让我检查一下我试图添加的东西
rewrite^/(.*)/$/$1
解决了这个问题,但产生了一个新问题。那么实际上有index.html的子文件夹就不起作用了。