我尝试添加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 这种格式有效,但据我所知,root不应该有尾随斜杠。
由于
答案 0 :(得分:5)
从此块中删除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;
中导致重复错误
答案 1 :(得分:1)
我有同样的问题, 如错误所示,通用配置重复了,nginx不喜欢它。您需要的一切都只是
/etc/nginx/snippets/fastcgi-php.conf:[line5]
并在该行的开头添加一个“#”,您可能还需要更改此文件上的更多行,这也与您的nginx配置有关