Routing - How to solve the problem that nginx cannot access files in the root directory?
PHP中文网
PHP中文网 2017-05-27 17:45:02
0
2
973

Mine is an Ubuntu16.04 host from Alibaba Cloud. The nginx installation was successful. When accessing the IP (for example: 0.0.0.0), the nginx welcome page is displayed, but when I access 0.0.0.0/index.html Displays 404, enter curl 127.0.0.1/index.html on the host to open the 404 page file. In other words, all files in the root directory have no routing. How to solve this problem?

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
洪涛

Ubuntu apt install nginx default configuration

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

/etc/nginx/sites-available/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 /etc/nginx/sites-available/default root line and change the directory to your own directory.

滿天的星座

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

server {
        listen       80;
        server_name  localhost;

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

The root attribute specifies the root directory where the accessed file is located, the index attribute specifies the default access page, and location / means matching all requests.

The page reports 404, then you go to the directory specified by root to check whether there is an index.html file

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template