Query string refers to GET parameters which you provide after URL e.g ?name=foo
. My guess is that you want to serve files in a directory instead, since you mention "out folder which we want to serve from Nginx".
In this case your example should work fine, but your try_files rule expects that you also provide the file name inside the URL.
So when you are requesting GET www.mysite.com then Nginx tries to find a
path inside the root
directory with either name /
, .html
, .html/
or fail with 404 error code. Path .html/
refers to a directory named .html
inside your root and is probably a mistake.
In case you have a file named index.html
in your specified root directory then following requests would match for it:
GET www.mysite.com/index.html
(because of $uri
)
GET www.mysite.com/index
(because of $uri.html
)
What you probably are looking for is this:
location / {
root /var/www/html/out;
index index.html index.htm;
try_files $uri $uri/ =404;
}
This does following:
- Is there an actual file, specified by $uri, in your root directory - then serve this.
- Is there a directory path, specified by $uri, in your root directory?
- If yes, check if it contains a file named index.html or index.htm - then serve this.
- None of the above, return 404.
So GET www.mysite.com
would try to find a file index.html
or index.htm
inside your root.
In case you still mean query strings you could write something like this:
location / {
root /var/www/html/out;
try_files /$arg_file =404;
}
Then request like GET www.mysite.com?file=index.html
would search for a file index.html
inside your root. Nginx is awesome, isn't it?
Hope this helps :)
Also read more about try_files and Nginx Pitfalls and Common Mistakes.