Question
How to fix 404 error nginx and Ubuntu 20 LTS
I was following along in a class in nginx when we got to creating a virtual host. They are using digital ocean in the tutorials, and I’m doing the same (I’ve been for years). I logged into my server and from the root directory created the sites/demo folder and put my html file in there.
I’m getting a 404 error that the file doesn’t exist, and it DOES EXIST. But I’m also getting some problems in the terminal when I try to list the contents of the folders:
root@WebServer:~# ls
sites snap var
root@WebServer:~# ls -l
total 12
drw-r--r-- 3 root root 4096 Oct 3 00:21 sites
drwxr-xr-x 3 root root 4096 Oct 2 22:40 snap
drw-r--r-- 3 root root 4096 Oct 2 23:08 var
root@WebServer:~# ls -l /sites/
ls: cannot access '/sites/': No such file or directory
root@WebServer:~# ls -l /sites
ls: cannot access '/sites': No such file or directory
root@WebServer:~# ls -l sites/
total 4
drw-r--r-- 2 root root 4096 Oct 3 00:22 demo
root@WebServer:~# cd sites
root@WebServer:~/sites# ls -l
total 4
drw-r--r-- 2 root root 4096 Oct 3 00:22 demo
root@WebServer:~/sites# ls -l /demo/
ls: cannot access '/demo/': No such file or directory
root@WebServer:~/sites# ls -l demo
total 4
-rw-r--r-- 1 root root 89 Oct 3 00:22 index.html
root@WebServer:~/sites# cd demo
root@WebServer:~/sites/demo# ls -l
total 4
-rw-r--r-- 1 root root 89 Oct 3 00:22 index.html
root@WebServer:~/sites/demo# cd ~
root@WebServer:~# ls -l sites/demo/
total 4
-rw-r--r-- 1 root root 89 Oct 3 00:22 index.html
root@WebServer:~#
My /etc/nginx/nginx.conf file:
events {}
http {
include /etc/nginx/mime.types;
server {
listen 80;
server_name 134.122.23.34;
root /sites/demo;
}
}
My error log for nginx:
2020/10/03 14:14:29 [error] 13135#13135: *1 "/sites/demo/index.html" is not found (2: No such file or directory), client: 71.224.30.124, server: 134.122.23.34, request: "GET / HTTP/1.1", host: "134.122.23.34"
2020/10/03 14:15:39 [error] 13161#13161: *2 "/sites/demo/index.html" is not found (2: No such file or directory), client: 71.224.30.124, server: 134.122.23.34, request: "GET / HTTP/1.1", host: "134.122.23.34"
2020/10/03 14:20:53 [error] 13161#13161: *3 "/sites/demo/index.html" is not found (2: No such file or directory), client: 83.97.20.29, server: 134.122.23.34, request: "GET / HTTP/1.0"
My access log:
71.224.30.124 - - [03/Oct/2020:14:14:29 +0000] "GET / HTTP/1.1" 404 153 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Safari/605.1.15"
71.224.30.124 - - [03/Oct/2020:14:15:39 +0000] "GET / HTTP/1.1" 404 153 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Safari/605.1.15"
83.97.20.29 - - [03/Oct/2020:14:20:53 +0000] "GET / HTTP/1.0" 404 153 "-" "-"
Can someone please help me understand why it isn’t seeing the files? I also tried creating a /var/www folder and got the same issues.
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.
×