Nginx error 16611 directory is forbidden

April 2, 2018 2.5k views
Nginx Ubuntu 16.04

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 redirect the url to ?

1 Answer

Does the /var/www/ directory have an index.html in it? The error would indicate that nginx was attempting to show a directory index which is usually done only after one of the listed index files cannot be found.

Have another answer? Share your knowledge.

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