Unlike apache, which turns directory browsing on by default, nignx turns directory browsing off by default. Here’s how to configure directory browsing in nginx.
Open the nginx.conf file and add it in the location server or http segments
autoindex on;
The other two parameters should be added:
autoindex_exact_size off;
The default is on, which shows the exact size of the file in bytes. When changed to off, the approximate size of the file is shown in units kB or MB or GB
autoindex_localtime on;
The default is off, and the file time displayed is GMT time. After changing to on, the time of the file displayed is the server time of the file
location /{
root /var/www/html;
autoindex on;
}
This code means to list the /var/www/html directory directly as the root directory.
If we want to display only one website or one directory, we can simply change all the.conf files on that website. If modified as follows:
server {
listen 80;
charset utf-8;
server_name localhost;
root /www/web/default;
location / {
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}
}