我试图添加try_files来检查php文件是否存在,但它给了我错误.
"try_files" directive is duplicate in /etc/nginx/snippets/fastcgi-php.conf:5
Run Code Online (Sandbox Code Playgroud)
这里我要添加try_files的位置
location ~ \.php$ {
try_files $uri =404;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm-user.sock;
}
Run Code Online (Sandbox Code Playgroud)
这是我的竞争服务器块.
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;
}
}
Run Code Online (Sandbox Code Playgroud)
我的服务器块出了什么问题?为什么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 这种格式有效,但是据我所知,root不应该有斜线.
谢谢
try_files从这个块中删除
location ~ \.php$ {
try_files $uri =404;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm-user.sock;
}
Run Code Online (Sandbox Code Playgroud)
您已经在snippets/fastcgi-php.conf;其中导致重复错误