Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set index.html as root file in Nginx?

How to set index.html for the domain name e.g. https://www.example.com/ - leads user to index.html in root directory.

I've tried different things like:

server {     # some configs      location = / {             index index.html;             fastcgi_index index.html;     } or      location / {             index index.html;             fastcgi_index index.html;     }  } 

Nothing helped me.

There are some other configs with location keyword, though I'd commented them either.

Other "location" configs in the server { clause:

location ~ .*(css|htc|js|bmp|jp?g|gif|ico|cur|png|swf|htm?|html)$ {         access_log off;         root $www_root; }  location ~ \.php$ {         include                         /etc/nginx/fastcgi_params;         index                           index.html;         fastcgi_index                   index.html;         fastcgi_param SCRIPT_FILENAME   $www_root$fastcgi_script_name;         fastcgi_param QUERY_STRING      $query_string;         fastcgi_param PATH_INFO         $fastcgi_path_info;         fastcgi_pass                    127.0.0.1:9000;         # Директива определяет что ответы FastCGI-сервера с кодом больше или равные 400         # перенаправлять на обработку nginx'у с помощью директивы error_page         fastcgi_intercept_errors        on;         break; }  location ~ /\.ht {     deny all; } 

All them were commented and uncommented, but nothing helped.

PS Editions were made in /etc/nginx/sites-enabled/domainname.com file.

like image 630
Arthur Kushman Avatar asked Aug 14 '12 14:08

Arthur Kushman


People also ask

How do I serve index HTML with nginx?

To serve static files with nginx, you should configure the path of your application's root directory and reference the HTML entry point as the index file. In this example, the root directory for the snake deployment is /home/futurestudio/apps/snake which contains all the files.

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. Generally, this is done, based on the website requirement or client requirements.


1 Answers

in your location block you can do:

location / {   try_files $uri $uri/index.html; } 

which will tell ngingx to look for a file with the exact name given first, and if none such file is found it will try uri/index.html. So if a request for https://www.example.com/ comes it it would look for an exact file match first, and not finding that would then check for index.html

like image 160
cobaco Avatar answered Sep 24 '22 00:09

cobaco