Nginx error 16611 directory is forbidden

My Nginx error.log has many error messages like this:

16611#16611: *1672714 directory index of “/var/www/” is forbidden, client:, server:, request: “GET /mydir/ HTTP/2.0”, host: “

When I enter in the browser the page is loaded ok.

My nginx config file has server block:

server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;

root /var/www/;
index index.html;

ssl_certificate     /etc/nginx/ssl/example/example.crt;
ssl_certificate_key /etc/nginx/ssl/example/example.key;
ssl_dhparam  /etc/nginx/ssl/example/dhparam.pem;

ssl_session_cache shared:SSL:20m;
ssl_session_timeout 10m;
ssl_session_tickets on;

ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/nginx/ssl/example/gd_bundle-g2-g1.crt;
resolver valid=300s;

ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

# Enable HSTS
#add_header Strict-Transport-Security "max-age=31536000; includeSubdomains" always;
#add_header Strict-Transport-Security "max-age=3600; includeSubdomains" always;
add_header Strict-Transport-Security "max-age=86400; includeSubdomains" always;
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options SAMEORIGIN;

# rewrite .htm to .html (tested ok)
location ~ \.htm$ {
    rewrite ^(.*)\.htm$ $1.html permanent; 

location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
    #expires 1h;
    expires 1d;
    #add_header Pragma public;
    #add_header Cache-Control "public";

location / {
    try_files $uri $uri/ =404;

# to run php from html file (also security.limit_extensions = .php .html in /etc/php5/fpm/pool.d/www.conf)
# location ~ \.(php|htm|html)$ {
location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    #include fastcgi_params;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    #fastcgi_index index.php;
    #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

What should I change in the config file to avoid the error and to add the url the index page index.html ?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Ryan Quinn
DigitalOcean Employee
DigitalOcean Employee badge
April 10, 2018
Accepted Answer

Based on your configuration I am guessing that nginx is refusing to provide a directory listing for this directory because your configuration does not include autoindex on;. This is generally a good thing.

Adding an index.html file to /var/www/ should prevent this and will return the page instead of attempting to create a directory listing.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel