• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

Nginx for Newbie: setting up autoindex directive

December 18, 2023

Nginx for Newbie: Setting Up Autoindex Directive

When it comes to web servers, Nginx is a popular choice due to its high performance, scalability, and ease of configuration. One of the essential features of Nginx is the autoindex directive, which allows you to generate directory listings automatically. In this article, we will explore how to set up the autoindex directive in Nginx for beginners.

What is the autoindex directive?

The autoindex directive in Nginx enables the automatic generation of directory listings when an index file is not found in a directory. It provides a convenient way to browse and access files on a web server without the need for a specific index file.

Enabling the autoindex directive

To enable the autoindex directive, you need to modify the Nginx configuration file. The configuration file is usually located in the /etc/nginx directory and named nginx.conf or default.conf. Open the file using a text editor of your choice.

Within the server block, locate the location block that corresponds to the directory you want to enable autoindex for. If the block does not exist, you can create one. Here’s an example:

location /path/to/directory {
    autoindex on;
}

In the above example, replace /path/to/directory with the actual path to the directory you want to enable autoindex for. The autoindex on; directive enables the autoindex feature for that specific location.

Customizing the autoindex appearance

By default, Nginx generates a simple directory listing with file names and sizes. However, you can customize the appearance of the autoindex page to match your website’s design. Nginx provides several options to modify the autoindex appearance.

For example, you can add the following directives within the location block to customize the header and footer:

location /path/to/directory {
    autoindex on;
    autoindex_format html;
    autoindex_localtime on;
    autoindex_exact_size off;
    add_before_body /path/to/header.html;
    add_after_body /path/to/footer.html;
}

In the above example, autoindex_format html; specifies that the directory listing should be in HTML format. autoindex_localtime on; displays the file modification time in the local time zone. autoindex_exact_size off; displays file sizes in human-readable format.

The add_before_body and add_after_body directives allow you to include custom header and footer files respectively. Replace /path/to/header.html and /path/to/footer.html with the actual paths to your header and footer files.

Restarting Nginx

After making changes to the Nginx configuration file, you need to restart the Nginx service for the changes to take effect. Open a terminal and run the following command:

sudo service nginx restart

Alternatively, you can use the following command if you are using systemd:

sudo systemctl restart nginx

Conclusion

The autoindex directive in Nginx is a powerful feature that allows you to generate directory listings automatically. By following the steps outlined in this article, you can easily set up the autoindex directive in Nginx and customize its appearance to match your website’s design. Start exploring the benefits of Nginx’s autoindex feature today!

For more information about VPS hosting and to explore our high-performance solutions, visit Server.HK.

Recent Posts

  • How to Host a Python Flask or Django Application on Hong Kong VPS (2026)
  • How to Set Up WireGuard VPN on a Hong Kong VPS: Step-by-Step Guide 2026
  • Hong Kong VPS vs DigitalOcean: Cost, Performance, and China Routing Compared (2026)
  • VPS Hosting vs Shared Hosting: Why the Upgrade Is Worth It for Asia-Facing Websites
  • Hong Kong VPS vs Google Cloud Asia: Which Delivers Better China Performance in 2026?

Recent Comments

  1. vibramycin injection on How to Choose the Right Hong Kong VPS Plan: A Buyer’s Guide for 2026
  2. allopurinol for gout on CN2 GIA vs BGP vs CN2 GT: What’s the Real Difference for China Connectivity?
  3. antibiotics online purchase on How to Set Up a WordPress Site on a Hong Kong VPS with aaPanel (Step-by-Step 2026)
  4. linezolid cost oral on Top 5 Use Cases for a Hong Kong Dedicated Server in 2026
  5. metoprolol generic on Hong Kong VPS vs Japan VPS: Head-to-Head for Asia-Pacific Deployments in 2026

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot