undefinedfix
Sign in

How to solve the problem that nginx can't access the files in the root directory?

antoaunix edited in Mon, 08 Feb 2021

My host is a ubuntu16.04 host of alicloud. Nginx has been successfully installed. When I visit the IP (e.g. 0.0.0), the nginx welcome page is displayed, but I visit 0.0.0.0/ index.html Display 404, input curl 127.0.0.1 in the host/ index.html Open is the 404 page file. That is to say, all files in the root directory have no routing. How can I solve this problem?

2 Replies
lihek
commented on Mon, 08 Feb 2021

Default configuration for installing nginx in Ubuntu apt

/etc/nginx/conf.d/ nginx.conf Default configuration

/Etc / nginx / sites available / default default default localhost configuration

/Var / www / HTML / default working directory

http://localhost/index.nginx-debian.html Default welcome page full URL


So you need to edit the line / etc / nginx / sites available / default root and change the directory to your own.

suxbr
commented on Mon, 08 Feb 2021

Conf in nginx installation directory/ nginx.conf The configuration is as follows:

server {
        listen       80;
        server_name  localhost;

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

The root attribute specifies the root directory of the file to be accessed, the index attribute specifies the default access page, and location / indicates that all requests are matched.

Page 404, then you go to the directory specified by root to see if there is index.html file

lock This question has been locked and the reply function has been disabled.