skip to Main Content

The problem

I have a website developed with NextJS, it is running on a server with Nginx. The website files are inside the public_html folder and running on port 3004, and i have a proxy_pass that redirect the requests to the NextJS website on port 3004.

But when I search for my domain or my site on google, it shows up in the results: Index of / (and the files inside)

I would like to remove this (and all the listing of files inside) to just put Home – Domain, for example.

Research and issue photos

Research and issue photos

My next.conf file

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;

        include /etc/nginx/default.d/*.conf;

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }

    server {
         listen 80;

         server_name computadorsolidario.tec.br www.computadorsolidario.tec.br;

         location / {
               autoindex off;
               proxy_pass http://localhost:3004;
               proxy_set_header Upgrade $http_upgrade;
               proxy_set_header Connection 'upgrade';
               proxy_set_header Host $host;
         }
    }
}

How can i solve this?

2

Answers


  1. You can turn off the feature of nginx where it creates directory listings:

    autoindex off;
    

    If you want to replace "index if /" with an actual home page, you would need to create an index.html file in document root directory.

    Login or Signup to reply.
  2. You should also add as a last location in your conf

    location ~ /. {
        deny all;
    }
    

    to block file access to dot files .env file or other sensitive data

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search