Adjusting NGINX for Visible Directories or Files

Before we begin

If you want to learn how to set up an NGINX server using your Raspberry Pi, here is a great post by Shane Pfaffly.

Create the directory

From the command line, navigate to your /var/www/ directory. Then create a new directory and name it whatever you desire.

sudo mkdir nameofyournewdirectory

Observe the current permissions

Use the following command to view the current permissions of the files and directories in /var/www/

ls -la

You'll see that some files and folders have root permission and some have NGINX permission. We want our newly created directory to have NGINX permission, that way NGINX can display it on your webserver.

Changing directory (or file) permissions

We'll use the following command and flags to add the directory (or file) to the NGINX permission group.

sudo chgrp -R nginx nameofyournewdirectory

Modify NGINX config file

Navigate to /etc/nginx/ and open the nginx.config file

sudo nano /etc/nginx/nginx.conf

Once you have the file open in Nano (or your preferred editor), locate 'location /' code block. Should look something like this..

location / {
  root /var/www/;
  index index.html index.htm;
}

We'll want add 'autoindex on;' to a new line in the code block. In result, it should look like this..

location / {
  root /var/www/;
  index index.html index.htm;
  autoindex on;
}

Save and exit.

Restart and test

Now we need to restart our NGINX server to make sure the newly modified config file gets loaded.

sudo service nginx restart

Once the server comes back up, try opening that directory in the browser. You may want to add a couple of test files to your new directory, so you can make sure they show up.