首页 > 解决方案 > /etc/nginx/nginx.conf:9 中“try_files”指令中的参数数量无效

问题描述

我是 Nginx 服务器的新手,但是在重新加载 Nginx 后我正在关注官方文档,我遇到了这个警报:

invalid number of arguments in "try_files" directive in /etc/nginx/nginx.conf:9

这是我的 nginx.conf 文件:

events{}


http{
        include /etc/nginx/mime.types;
        server{listen 80;
              server_name x.x.x.x;
              root /var/www/html/;
              try_files /error;


              location =rediect {return 307 http://www.facebook.com;}
              location /error {return 200 "we overcome the error ";}
              location =/right{ return 200 "you are right"; }
              location =/time{return 200 "$time_local";}
              location =/host{return 200 "$hostname";}
              location =/redirect{return 301 http://www.facebook.com;}
             #location / {access_log /var/log/nginx/new.log;}
              location / {access_log /var/log/nginx/last.log ;}
             }
   } 

**Where is x.x.x.x is my machine ip.**

标签: nginx

解决方案


习惯于阅读文档,尤其是像这样直截了当的问题。我知道你是 nginx 的新手,但谷歌搜索“nginx try_files”会比在这里输入问题要快得多。

无论如何,你会在这里结束:

http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files

语法:try_files 文件 ... uri;

按指定顺序检查文件是否存在,并使用第一个找到的文件进行请求处理;处理在当前上下文中执行。文件的路径是根据根和别名指令从文件参数构造的。可以通过在名称末尾指定斜杠来检查目录是否存在,例如“$uri/”。如果没有找到任何文件,则内部重定向到最后一个参数中指定的 uri。


推荐阅读