# nginx url index.php/page/Gallery.html returns 404

sorry if this is a repeat, please just link me if so.

this is my first time setting up nginx. (its under virtualmin and debian)

it serves php fine, such as index.php

but the url index.php/page/Gallery.html returns 404

im guessing it can't decipher the request string but not sure what to do about it

i dont believe in that form it is using rewrite (something i will setup once i get without working)

its nginx/0.7.67 and the error log message is:

2013/01/13 16:19:47 [error] 5170#0: *123 open() "/public_html/index.php/page/Profile.html" failed (20: Not a directory), client: ip, server: .com.au, request: "GET /index.php/page/Profile.html HTTP/1.1", host: ".com.au", referrer: "http://.com.au/"

THANKS !

server {
server_name ....com.au www.....com.au;
listen 118.8...;
root /home/.../public_html;
index index.html index.htm index.php;
access_log /var/log/virtualmin/....com.au_access_log;
error_log /var/log/virtualmin/....com.au_error_log;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
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_FILENAME /home/.../public_html$fastcgi_script_name; fastcgi_param SCRIPT_NAME$fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI$document_uri;
fastcgi_param DOCUMENT_ROOT /home/.../public_html;
fastcgi_param SERVER_PROTOCOL $server_protocol; 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;
location ~ \.php${ try_files$uri =404;
fastcgi_pass localhost:9000;
}


}

-
You have no rewrite set up at all? That would be the problem. See: wiki.nginx.org/HttpRewriteModule –  SLD Jan 14 '13 at 22:54
this may highlight my newbness but do i need them at this stage with this url ? ive add the server conf from virtualmin –  Hayden Thring Jan 14 '13 at 22:57
With no rewrite set up it's behaving exactly as apache would and reads /public_html/index.php/page/Profile.html as a folder structure but it knows that index.php is a file hence the error. You need to rewrite everything to the right of index.php to be passed as a query string. Are you using a framework? –  SLD Jan 14 '13 at 23:02
yes jaws cms jaws-project.com –  Hayden Thring Jan 15 '13 at 4:43

You could simply use this

try_files $uri$uri/ /index.php;

What this would do is try to find the file or the directory, and if neither is found, fall back to the index.php file. That way you could just use domain.com.au/page/Gallery.html (assuming there isn't a file with that name). Then you would just use the index.php to load the data. You could also then use it to handle 404 errors, making users see a nice page themed the same as the rest of the site.

However, if you have to use it in that format, you could change it to this

location ~ \index.php/ {
try_files $uri$uri/ /index.php;
fastcgi_pass localhost:9000;
}
location ~ \.php${ try_files$uri =404;
fastcgi_pass localhost:9000;
}

This will retain a handler for .php files, while also give you a separate one for when the url contains index.php/.

-
this worked, but im still a bit confused why i needed this when on apache this url works without a .htaccess, is it that apache already has a rule like this built in ? –  Hayden Thring Jan 15 '13 at 4:44
Apache is much more entwined with PHP (at least in the usual distributions that don't use fcgi), so it's a bit better at detecting php files and what should be run by what. Nginx only does what you tell it to, which is, from a security standpoint, a bit better. –  Sašo Jan 15 '13 at 9:24
thanks for that comment –  Hayden Thring Jan 17 '13 at 11:28

with a bit of experimenting i got the provided answer to work when not using index.php 's in jaws cms (rewrite enabled)

location ~ \.php${ try_files$uri =404;
fastcgi_pass localhost:9000;
}
location ~ \index.php/ {
try_files $uri$uri/ /index.php;
fastcgi_pass localhost:9000;
}
location / {
try_files $uri$uri/  /index.php/\$uri;
}

-