EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Nginx Tutorial Nginx Autoindex
Secondary Sidebar
Nginx Tutorial
  • Basic
    • Nginx Add_header
    • Nginx FastCGI
    • Nginx WAF
    • Nginx Forward Proxy
    • Nginx Ingress Annotations
    • Nginx Location Directive
    • Nginx User
    • Nginx Port
    • Nginx Auth_request
    • Nginx Autoindex
    • Nginx if else
    • Nginx uWSGI
    • Nginx X-Forwarded-For
    • Nginx GUI
    • NGINX Unit
    • NGINX if
    • Nginx default_server
    • Nginx worker_connections
    • Nginx Authentication
    • Nginx Gateway Timeout
    • Nginx Error_page
    • Nginx Server Block
    • Nginx Forbidden
    • Nginx Modules
    • Nginx Max Upload Size
    • Nginx vs LiteSpeed
    • Nginx multiple server_name

Nginx Autoindex

Nginx Autoindex

Definition of Nginx Autoindex

Nginx autoindex is used the ngx http autoindex module to process the requests which was ending with the “/” slash character and it will produce the listing directory. Basically, the request is passed by using the ngx http autoindex module when the specified module will not find the index. If suppose we are using the nginx as a web server and we want to display an nginx directory with nginx autoindex.

What is Nginx Autoindex?

We can achieve by creating the index.html file, for creating autoindex we need to use the ngx http autoindex module. If suppose we don’t have an index.html file in a specified directory which we want to generate, then we can navigate the URL and path, and the same will return the error 404 i.e. page not found. However, the autoindex in nginx is providing an easy way for a directory that is particular to generate a listing automatically. Adding nginx autoindex in the nginx configuration file is very easy. Below is the syntax shown to add into the nginx configuration file is as follows.

Syntax –

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

location /directory_name/ {

autoindex on;

}

In the above syntax, location is nothing but the directory location on which we have specified the directory. Location is the directive uses in nginx. The directory name specifies the name of a directory which we are using for specifying the location. The name of the directory is very important. We also need to define the autoindex parameter to use the autoindex in the nginx configuration file.

At the time when we did the above changes, we need to restart the nginx server, without restarting the nginx server those parameter is not affecting the current environment. After restarting the nginx server now instead of returning the 404 (page not found) error the web server will return the index of the nginx directory. It is very useful and important to list the index automatically. We can define the indexes by using directives of nginx autoindex. There are multiple directives are available in the nginx to define the indexes.

How to Change nginx autoindex?

We can change the autoindex in nginx using the following steps.

  1. In the first step, we need to install the nginx server in our system. We can install the nginx server by using rpm, source as well as by using the binary installation.
apt-get install nginx

lkioprt

2. After installing the server of nginx, we need to start the nginx server by using “service nginx start” command. After starting the nginx service we can check the status of the service. We have installed the nginx version as 1.18 as follows.

service nginx status
nginx –V

loper

3. In this step we are creating the directory of our website from which we are using the auto indexes. We are creating the directory name as nginx_autoindex. After creating the directory we are providing the 755 umask value to the specified directory as follows.

mkdir -p /nginx_autoindex

chmod -R 755 /nginx_autoindex

fgt

4. After creating the directory and providing the umask value to the same now we are opening the nginx configuration file to add the configuration of nginx autoindex as follows.

klop

5. After opening the configuration files now we are adding the nginx autoindex configuration into the configuration files. We are adding the below code into the configuration file as follows.

Code –

location /nginx_autoindex/ {

autoindex on;

}

7

6. To take the effect of the above change we need to restart the nginx server by using the following command. Before that, we need to check that our configuration is valid in the nginx configuration file by using the following command.

nginx –t

service nginx restart

rty

Nginx autoindex module

While using autoindex on or off we can also use three directives modules as follows.

  • autoindex_exact_size – This directive of the nginx autoindex will specify that nginx will display the exact size of the file for the output into the index. This directive into the nginx module contains two options, i.e. on or off.
  • autoindex_format – This directive will specify which format of the nginx index will be listed and the same has been output. This directive contains the four types of options, i.e. xml, json, jsonp, and html.
  • autoindex_localtime – This directive in the module will specify whether directory time should be output as UTC or time which was local. This directive into the nginx autoindex module contains two options i.e. on and off.

The below example shows the nginx module of autoindex as follows. In the below example, we are using all the directives.

Code –

location /nginx_autoindex/ {

autoindex on;

autoindex_exact_size off;

autoindex_format html;

autoindex_localtime on;

}

ler

Nginx autoindex Example

We have already installed the nginx server so we have no need to install it again.

First, we are creating the data directory name as nginx_autoindex_example for defining the example. After creating the directory then we are providing the 755 umask value to this directory as follows.

mkdir -p /nginx_autoindex_example

chmod -R 755 /nginx_autoindex_example

jkldf

After creating the directory name as nginx_autoindex_example now we are opening the configuration file of nginx to add the configuration.

Nginx Autoindex jkrt

After opening the file of nginx configuration now we are adding the following configuration into the nginx configuration file as follows. We are adding autoindex_exact_size and autoindex_format parameter by using autoindex as an option.

Code –

location /nginx_autoindex/ {

autoindex on;

autoindex_exact_size off;

autoindex_format xml;

}

Nginx Autoindex fre

After adding the autoindex configuration now we are checking the syntax and restarting the nginx server.

nginx –t

service nginx restart

Nginx Autoindex ke3

Conclusion

We can achieve this by creating the index.html file, for creating autoindex we need to use the ngx http autoindex module. Basically, the request is passed by using the ngx http autoindex module when the specified module will not find the index.

Recommended Articles

This has been a guide to Nginx Autoindex. Here we discussed the Definition, What is Nginx Autoindex, How to Change it with examples and code implementation. You can also go through our other suggested articles to learn more –

  1. Nginx Port
  2. Nginx Location Directive
  3. Nginx Ingress Annotations
  4. Nginx User
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more