在fastcgi-php.conf上尝试“php文件导致错误”;试试“U文件”;指令在/etc/nginx/snippets/fastcgi php.conf:5中重复

在fastcgi-php.conf上尝试“php文件导致错误”;试试“U文件”;指令在/etc/nginx/snippets/fastcgi php.conf:5中重复,php,nginx,Php,Nginx,我试图添加try_文件来检查php文件是否存在,但它给了我错误 "try_files" directive is duplicate in /etc/nginx/snippets/fastcgi-php.conf:5 这里是我要添加try\u文件的位置 location ~ \.php$ { try_files $uri =404; include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-

我试图添加try_文件来检查php文件是否存在,但它给了我错误

"try_files" directive is duplicate in /etc/nginx/snippets/fastcgi-php.conf:5
这里是我要添加try\u文件的位置

location ~ \.php$ {
    try_files $uri =404;
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.0-fpm-user.sock;
}
这是我的服务器块

server {
    listen 80;
    server_name www.example.com example.com;
    return 301 https://example.com$request_uri;
}



server {
    listen 443 ssl;
    server_name www.example.com;
    ssl_certificate /home/user/ssl/example.com.ssl-bundle.crt;
    ssl_certificate_key /home/user/ssl/example.com.key;
    return 301 https://example.com$request_uri;
}



server {
    listen 443 ssl;

    root /home/user/public_html;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name example.com;
    ssl_certificate /home/user/ssl/example.com.ssl-bundle.crt;
    ssl_certificate_key /home/user/ssl/example.com.key;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

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

    include /home/user/public_html/nginx.conf;

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

    location ^~ /wp-login.php {
        auth_basic "Administrator Login";
        auth_basic_user_file /etc/nginx/.htpasswd;
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm-user.sock;
    }

    location /phpmyadmin {
        auth_basic "Restricted Content";
        auth_basic_user_file /etc/nginx/.htpasswd;
    }

    # Phpmyadmin Configurations
    location /phpmyadmin {
        root /home/user/public_html/;
        index index.php index.html index.htm;
        auth_basic "Restricted Content";
        auth_basic_user_file /etc/nginx/.htpasswd;
        location ~ ^/phpmyadmin/(.+\.php)$ {
            try_files $uri =404;
            root /home/user/public_html/;
            fastcgi_pass unix:/run/php/php7.0-fpm-user.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
        location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
            root /home/user/public_html/;
        }
    }

    location /phpMyAdmin {
        rewrite ^/* /phpmyadmin last;
    }

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

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

}
我的服务器块怎么了?为什么try_文件给我错误?是fastcgi-php.conf错误吗?我的Nginx版本是1.12.1

另一个问题,请检查我的phpmyadmin块,我从这里得到它 这种格式有效,但据我所知,根不应该有尾部斜杠


谢谢

从此块中删除
尝试\u文件

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

您已经在
snippets/fastcgi-php.conf中找到了它导致重复错误

从此块中删除
重试文件

location ~ \.php$ {
    try_files $uri =404;
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.0-fpm-user.sock;
}
您已经在
snippets/fastcgi-php.conf中找到了它导致重复错误

我也有同样的问题, 正如错误所说,有重复的公共配置,这是nginx不喜欢的。你所需要的一切都会消失

/etc/nginx/snippets/fastcgi-php.conf:[line5]
并在行的开头添加一个“#”,您可能需要在此文件中更改更多关于nginx配置的行, 正如错误所说,有重复的公共配置,这是nginx不喜欢的。你所需要的一切都会消失

/etc/nginx/snippets/fastcgi-php.conf:[line5]

并在行的开头添加一个“#”,您可能还需要在此文件中更改更多关于nginx配置的行

我明白了,但为什么我不能使用
try_files$uri=403也是吗?如果我使用的是
snippets/fastcgi-php.conf,我甚至不能使用不同的
try_文件
编辑:我的坏,不能在一个位置上使用超过1个
try\u文件
。我现在太累了:D关于phpmyadmin根使用尾部斜杠的第二个问题怎么样?@somuch72,试着在帖子中保留一个问题。因此,我看到评论和发布解决方案更容易,但为什么我不能使用
try_files$uri=403也是吗?如果我使用的是
snippets/fastcgi-php.conf,我甚至不能使用不同的
try_文件
编辑:我的坏,不能在一个位置上使用超过1个
try\u文件
。我现在太累了:D关于phpmyadmin根使用尾部斜杠的第二个问题怎么样?@somuch72,试着在帖子中保留一个问题。因此,评论和发布解决方案更容易,因为这会停止错误状态——这也会产生阻止解析PHP的不良效果。虽然这会停止错误状态,但也会产生阻止解析PHP的不良效果。