2017-08-26 143 views
0

我嘗試添加try_files來檢查php文件是否存在,但它給我錯誤。try_files for php在fastcgi-php.conf中導致錯誤,「try_files」指令在/etc/nginx/snippets/fastcgi-php.conf中重複:

"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的錯誤?我的Nginx版本是1.12.1

另一個問題,請檢查我的phpmyadmin塊,我從這裏得到它https://serverfault.com/questions/433785/nginx-phpmyadmin-redirecting-to-instead-of-phpmyadmin-upon-login 這種格式的工作,但據我所知,根本不應該有尾隨斜線。

感謝

回答

1

從此塊

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;這也是造成重複錯誤

+0

我明白,但爲什麼我不能用'try_files $ URI刪除try_files = 403;'也是?如果我使用'snippets/fastcgi-php.conf;我甚至不能使用不同的'try_files''編輯:我的壞,不能在一個位置使用超過1個'try_files'。我現在很累:D我的第二個問題關於phpmyadmin root使用尾部斜槓怎麼樣? – somuch72

+0

@ somuch72,嘗試在帖子中保留一個問題。因此,評論和發佈解決方案更容易 –