首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Try_files指令在/etc/nginx/Try_files/ fastcgi-php.conf中重复

Try_files指令在/etc/nginx/Try_files/ fastcgi-php.conf中重复
EN

Stack Overflow用户
提问于 2017-08-27 05:40:45
回答 2查看 5.7K关注 0票数 1

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

"try_files" directive is duplicate in /etc/nginx/snippets/fastcgi-php.conf:5

这里是我想要添加try_files的位置

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_files会给我错误?是fastcgi-php.conf bug吗?我的Nginx版本是1.12.1

另一个问题,请检查我的phpmyadmin代码块,我从这里得到它,这种格式可以工作,但据我所知,https://serverfault.com/questions/433785/nginx-phpmyadmin-redirecting-to-instead-of-phpmyadmin-upon-login不应该有尾部斜杠。

谢谢

EN

回答 2

Stack Overflow用户

发布于 2017-08-27 05:49:24

从此块中删除try_files

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;中拥有该文件,这将导致重复错误

票数 9
EN

Stack Overflow用户

发布于 2018-08-21 06:56:25

我也遇到了同样的问题,因为错误提示有重复的通用配置,nginx不喜欢它。你所需要的一切都会

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

并在行首添加"#“,您可能还需要更改此文件中与nginx配置相关的更多行

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45899899

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档