title: 403 Forbidden: directory index of "/path/to/files" is forbidden Nginx
body: <p>I want to be really careful here because I just had to destroy my entire server and build again from scratch (total nightmare) because I tried fixing this error following advice such as </p>
  
  <pre><code>sudo chown -R user:user *
  sudo chmod 755 [directory name]
  sudo chmod 644 *
  </code></pre>
  
  <p>and ended up severely screwing up my permissions and breaking the whole Ubuntu system.</p>
  
  <p>I've also followed the advice from other similar questions to take out the second <code>$uri</code> from my Nginx config and that has not fixed the problem. </p>
  
  <p>My <code>user1</code> has root privileges given by <code>usermod -aG sudo user1</code> </p>
  
  <p>My Nginx error log says</p>
  
  <pre><code>2019/03/06 17:45:40 [error] *1 directory index of "/home/user1/app/src/apr/" is forbidden
  </code></pre>
  
  <p>And my domain name shows </p>
  
  <pre><code>403 Forbidden
  </code></pre>
  
  <p><code>ps -ef | grep nginx</code> returns </p>
  
  <pre><code>root     15419     1  0 17:45 ?        00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
  www-data 15420 15419  0 17:45 ?        00:00:00 nginx: worker process
  user1  15503 15462  0 18:00 pts/1    00:00:00 grep --color=auto nginx
  </code></pre>
  
  <p>My nginx config</p>
  
  <pre><code>server {
      listen 80;
      #listen [::]:80 ipv6only=on;
  
      server_name your.server.com;
      access_log /etc/nginx/access.log;
  
      root /var/www/html/someroot;
  
      location / {
              #autoindex on;
  
              # First attempt to serve request as file, then
              # as directory, then fall back to displaying a 404.
              # try_files $uri =404;
  
              #proxy_set_header X-Real-IP $remote_addr;
              #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              #proxy_set_header Host $http_host;
              #proxy_set_header X-NginX-Proxy true;
              #proxy_pass http://127.0.0.1:8080/;
              #proxy_redirect off;
              #proxy_http_version 1.1;
              #proxy_set_header Upgrade $http_upgrade;
              #proxy_set_header Connection "upgrade";
  
              #proxy_redirect off;
              #proxy_set_header   X-Forwarded-Proto $scheme;
              #proxy_cache one;
              #proxy_cache_key sfs$request_uri$scheme;
      }
  
      listen 443 ssl; # managed by Certbot
      ssl_certificate /etc/letsencrypt/live/some/fullchain.pem;
      # managed by Certbot
      ssl_certificate_key /etc/letsencrypt/live/some/privkey.pem; 
      # managed by Certbot
      include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
  
      if ($scheme != "https") {
          return 301 https://$host$request_uri;
      }
  }
  </code></pre>