I'm trying to get Nginx running from source in the user folder of my shared host with debian-style directory structure. I'm getting an error when I try to start the server up:
[emerg] invalid number of arguments in "try_files" directive in /home/.../nginx/conf/sites-enabled/default:11
The line referenced is the PHP execution protection from the Nginx pitfalls page. Here are my config files:
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/*;
}
...and sites-available/default:
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;
}
}
I can't find anything wrong with my configs. My setup is almost identical to a working installation on an Ubuntu box I'm running. What am I doing wrong?
EDIT: Upon further testing, this only happens when I'm using a sites-available setup with an include in nginx.conf. If I copy/paste the contents of my sites-available/default into my nginx.conf everything works fine.
EDIT2: As mentioned, if I removed try_files from the vhosts file it fails again with the same error on fastcgi_params. Here is the contents of my fastcgi_params file. It is all default:
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: I made a slight mistake. It's fastcgi_param, not fastcgi_param*s* where the error contiunes after removing the try_files directive.
The try_files directive commonly uses the $uri variable, which represents the part of the URL after the domain name. In the following example, NGINX serves a default GIF file if the file requested by the client doesn’t exist.
If disabled, redirects issued by nginx will be relative. See also server_name_in_redirect and port_in_redirect directives. This directive appeared in version 0.8.11.
Parameter value can contain variables (1.17.0). This directive appeared in versions 1.1.0 and 1.0.6. Controls how nginx closes client connections. The default value “ on ” instructs nginx to wait for and process additional data from a client before fully closing a connection, but only if heuristics suggests that a client may be sending more data.
Not all guides out there are wrong, but a scary number of them are. These docs were created and reviewed by community members that work directly with all types of NGINX users. This specific document exists only because of the volume of common and recurring issues that community members see.
Nginx tries to explain that the try_files
directive needs at least two paths:
try_files /path1$uri /path2$uri ...
Use either /dev/null
as a simple work-around:
try_files $uri /dev/null =404;
Or a named location that allows for more customization:
try_files $uri @error
...
location @error {
...
}
Not sure if this is your issue, but I've got my try_files outside the PHP location block:
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
....
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With