nginx のデフォルト ルートはポート 80 で 404 を返します

nginx のデフォルト ルートはポート 80 で 404 を返します

ポート 80 の IP のみを使用してサーバーにアクセスしようとすると問題が発生します。

IP にアクセスすると、nginx 404 エラー ページが表示されます。

私のデフォルトの設定は次のようになります:

# You may add here your
# server {
#       ...
# }
# statements for each of your virtual hosts to this file


server {
        listen    80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default ipv6only=on; ## listen for ipv6
        # Document root
        root /var/www/default;
        index index.html index.htm;

        # Make site accessible from http://localhost/
        server_name localhost;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                try_files $uri $uri/ /index.html;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

        location /doc/ {
                alias /usr/share/doc/;
                autoindex on;
                allow 127.0.0.1;
                deny all;
        }

        # Only for nginx-naxsi : process denied requests
        #location /RequestDenied {
                # For example, return an error code
                #return 418;
        #}

        #error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page 500 502 503 504 /50x.html;
        #location = /50x.html {
        #       root /usr/share/nginx/www;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #       fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
        #       fastcgi_pass unix:/var/run/php5-fpm.sock;
        #       fastcgi_index index.php;
        #       include fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}

内部に/var/www/defaultindex.html というファイルがあります。ここで奇妙な部分に移ります。listen ポートを に変更すると、8888nginx は index.html を正しく提供します。サイトは 3 つしかなく、他のサイトは仮想ホストなので、listen ディレクティブはありません。今のところ/var/www/defaultフォルダーを に設定しましたが、依然としてポート で返されます。chmod 77740480

編集: nginx のエラー ログを確認したところ、次のように記載されていました: 2014/04/08 09:30:21 [error] 3349#0: *1 "/etc/nginx/html/index.html" is not found

/etc/nginx/html/index.htmlすると、デフォルトのルートであることを示すこの構成はどこにあるかという疑問が生じます。

答え1

default_serverディレクティブにオプションがありませんlisten。そのため、リクエストは nginx 構成内の他の仮想ホストと一致します。

それで、これをリスニングラインとして試してみてください:

listen 80 default_server;

default_serverその後、他の仮想ホストにその定義がある場合は、その仮想ホストから を削除する必要があるかもしれません。

他に考えられるのは、 または を使用してサーバーにアクセスしたか127.0.0.1どうかですlocalhost。 は、URL で が使用されているserver_name localhost場合にのみ仮想ホストが使用されることを意味します。localhost

関連情報