Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I serve a single file in a location directive?

Tags:

nginx

How do I return a single file in location directive without any fallbacks? try_files needs at least two. This seems simple but I can't find it in the docs or examples.

location / {
      try_files one_file; # => wrong number of parameters
}
like image 470
user492922 Avatar asked Oct 30 '13 00:10

user492922


People also ask

How do I use NGINX as a file server?

Serving static files using nginx as web server is a good option. For making the static files available you need to copy your testfolder to /usr/share/nginx/html inside the nginx image. After which you will be able to see the files on your browser on port 8080.

Where does NGINX find static files?

Root Directory and Index Files mp3 or . mp4 extension, NGINX instead searches for the file in the /www/media/ directory because it is defined in the matching location block. You can list more than one filename in the index directive. NGINX searches for files in the specified order and returns the first one it finds.

Where do I put html files in NGINX?

By default Nginx Web server default location is at /usr/share/nginx/html which is located on the default file system of the Linux.


Video Answer


1 Answers

The simplest way is to use the ability to redirect to an error code if the file doesn't exist.

location / {
      try_files /theOnlyFile.html =404;
}
like image 147
Danack Avatar answered Sep 19 '22 13:09

Danack