nginxはポート80と443の両方を提供しますが、常にポート80でHTTP 404を返します。

nginxはポート80と443の両方を提供しますが、常にポート80でHTTP 404を返します。

私はRaspberry Pi 4でnginx v1.22.1(Debian Bookwormベース)を実行しています。 nginxは、Not FoundHTTP / portを介したすべての要求に対してHTTP 404を返します80

ここに画像の説明を入力してください。

ただし、HTTPS / portではすべてがうまく機能します443

これは私のものです/etc/nginx/nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;
error_log /var/log/nginx/error.log;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
}

http {
        sendfile on;
        tcp_nopush on;
        types_hash_max_size 2048;
        include /etc/nginx/mime.types;
        default_type application/octet-stream;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;
        access_log /var/log/nginx/access.log;
        gzip on;
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

これは私が設定したウェブサイトですetc/nginx/sites-enabled/myraspi.conf

server {
    listen 80;

    location /hello {
        add_header Content-Type text/html;
        return 200 'Here I am!';
    }
}

server {
    listen 443 ssl;
    ssl_certificate /etc/ssl/certs/myraspi.fritz.box.crt;
    ssl_certificate_key /etc/nginx/ssl/certificates/myraspi.fritz.box.pem;

    location /world {
        add_header Content-Type text/html;
        return 200 'Here I am!';
    }
}

電話をかけることはできますが、HTTPS GET myraspi/world機能しませんHTTP GET myraspi/hello。ただし、エラーページにnginxフッターが含まれているため、nginx設定の問題のようです。

nginxが両方のポートでリッスンしていることを確認しました。状況は次のとおりです。

myuser@myraspi:/etc/nginx $ sudo netstat -nlp | grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1972636/nginx: mast
tcp6       0      0 :::80                   :::*                    LISTEN      1972636/nginx: mast

myuser@myraspi:/etc/nginx $ sudo netstat -nlp | grep 443
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      1972636/nginx: mast

構成の確認sudo nginx -tも成功します。

myuser@myraspi:/etc/nginx $ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

エラーログには/var/log/nginx/error.logエラーは含まれず、アクセスログに着信/var/log/nginx/access.log要求が表示されます。

<<my IPv6 IP address>> - - [30/Mar/2024:13:35:03 +0100] "GET /hello HTTP/1.1" 404 125 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0"

何が間違っているのかというアイデアはありますか?

ありがとうございます!

ベストアンサー1

etc/nginx/sites-enabled/myraspi.confIPv6サポートを追加するには、次の行を追加する必要がありました。

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

    location /hello {
        add_header Content-Type text/html;
        return 200 'Here I am!';
    }
}

おすすめ記事