0

I have set up a vanilla installation of nginx on a raspberry pi.

server configuration:

server {
    listen 80;
    listen [::]:80;

    root /home/pi/www;

    index index.html index.htm;

    server_name _;

    location / {
        # return 418 on not found. non standard but a useful test
        try_files $uri $uri/ =418;
    }
}

curling through localhost, I get a response. curling the hostname I get 404. There is no entry in the access log for the latter, only the former:

pi@pik3s $ hostname
pik3s
pi@pik3s $ curl localhost
<h1>HELLO</h1>
pi@pik3s $ curl pik3s
404 page not found
pi@pik3s $ tail /var/log/nginx/access.log
::1 - - [22/Jun/2021:13:51:32 +0100] "GET / HTTP/1.1" 200 15 "-" "curl/7.64.0"

I don't understand where the 404 is coming from as I'm returning 418 for not found as a test, and the 404 doesn't seem to hit nginx at all.

updated: 2021-06-23: i set the error log to 'debug' and this is the contents:

$ cat /var/log/nginx/error.log
2021/06/23 10:53:00 [debug] 15325#15325: epoll add event: fd:6 op:1 ev:10000001
2021/06/23 10:53:00 [debug] 15325#15325: epoll add event: fd:7 op:1 ev:10000001
2021/06/23 10:53:00 [debug] 15326#15326: epoll add event: fd:6 op:1 ev:10000001
2021/06/23 10:53:00 [debug] 15326#15326: epoll add event: fd:7 op:1 ev:10000001
2021/06/23 10:53:00 [debug] 15328#15328: epoll add event: fd:6 op:1 ev:10000001
2021/06/23 10:53:00 [debug] 15328#15328: epoll add event: fd:7 op:1 ev:10000001
2021/06/23 10:53:00 [debug] 15330#15330: epoll add event: fd:6 op:1 ev:10000001
2021/06/23 10:53:00 [debug] 15330#15330: epoll add event: fd:7 op:1 ev:10000001

ie, the request seems to be stopping before it gets to nginx.

updated: 2021-06-25: checked curl -v and localhost returns Server: nginx/1.14.2 while pik3s returns no Server.

I realised that /etc/hosts only resolves pik3s to an IPv4 address, so I added ::1 as an alternative, and now it works (on the local machine).

So this suggests that nginx is only listening on IPv6.

$ sudo netstat -ltnp | grep :80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      26923/nginx: master 
tcp6       0      0 :::80                   :::*                    LISTEN      26923/nginx: master 

but it is listening.

dma
  • 101
  • 2

0 Answers0