我正在尝试使用debian样式目录结构从共享主机的用户文件夹中的源代码运行Nginx。尝试启动服务器时出现错误:
[emerg] invalid number of arguments in "try_files" directive in /home/.../nginx/conf/sites-enabled/default:11
所引用的行是Nginx陷阱页面中的PHP执行保护。这是我的配置文件:
nginx.conf:
worker_processes 1;
events {
worker_connections 1024;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 5m;
include /home/hittingsmoke/nginx/conf/mime.types;
default_type application/octet-stream;
gzip on;
gzip_disable \"msie6\";
include /home/hittingsmoke/nginx/conf/sites-enabled/*;
}
...以及可用网站/默认网站:
server {
listen 12513;
root /home/hittingsmoke/nginx/html/;
index index.php index.html index.htm;
server_name _;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/home/hittingsmoke/php-5.3/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
我的配置找不到任何错误。我的设置几乎与我正在运行的Ubuntu盒上的有效安装相同。我究竟做错了什么?
编辑:经过进一步测试,这仅在我使用包含nginx.conf中包含内容的站点可用安装程序时发生。如果我将网站的内容(可用/默认)复制/粘贴到我的nginx.conf中,则一切正常。
EDIT2:如上所述,如果我从vhosts文件中删除了try_files,它将再次失败,并且在fastcgi_params上出现相同的错误。这是我的fastcgi_params文件的内容。都是默认的:
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
EDIT3:我犯了一个小错误。它是fastcgi_param,而不是fastcgi_param * s *,在删除try_files指令后错误继续存在。
最佳答案
Nginx试图解释try_files
指令至少需要两条路径:
try_files /path1$uri /path2$uri ...
使用
/dev/null
作为简单的解决方法: try_files $uri /dev/null =404;
或允许更多自定义的命名位置:
try_files $uri @error
...
location @error {
...
}
关于Nginx "invalid number of arguments in "try_files“指令...”用于PHP安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17349616/