首页 > 解决方案 > 为什么这个 404 超时?

问题描述

有人可以解释为什么页面超时需要 30 秒吗?根据 Chrome 的调试器,它正在等待 404。

在此处输入图像描述

我不明白。如果是 404,为什么不立即返回 page not found 呢?

有问题的 nginx 配置看起来像这样

# redirect http to https
server {
    listen ${API_PORT} default_server;
    listen [::]:${API_PORT} default_server;
    server_name example-api.${SITE_SUFFIX};
    return 301 https://$host$request_uri;
}

server {
  set $indexhtml 'index.html';

     # port to example on. Can also be set to an IP:PORT
   listen 8443 ssl;

   # sets the domain[s] that this vhost server requests for
  server_name example.${SITE_SUFFIX};
  ssl_certificate     /certs/example.${SITE_SUFFIX}/fullchain.pem;
  ssl_certificate_key /certs/example.${SITE_SUFFIX}/privkey.pem;
  proxy_ssl_ciphers   HIGH:!aNULL:!MD5;

  client_max_body_size 4G;
  keepalive_timeout 10;


  if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$ ){
    return 405;
  }

  root /var/www/frontend/public;

  error_page 404 @404;

  include conf.d/sites/content.conf;

  # error page location redirect 302
  location @404 {
      return 302 /404;
  }
}

server {
  # port to example on. Can also be set to an IP:PORT
  listen 8443 ssl;

   # sets the domain[s] that this vhost server requests for
  server_name sl.example.${SITE_SUFFIX};
  ssl_certificate     /certs/sl.example.${SITE_SUFFIX}/fullchain.pem;
  ssl_certificate_key /certs/sl.example.${SITE_SUFFIX}/privkey.pem;
  proxy_ssl_ciphers   HIGH:!aNULL:!MD5;
  
  client_max_body_size 4G;
  keepalive_timeout 10;


  if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$ ){
    return 405;
  }

  error_page 404 @404;

  include conf.d/sites/sh.conf;

  # error page location redirect 302
  location @404 {
      return 302 /404;
  }
}

更新

这是超时后的样子。

在此处输入图像描述

标签: debuggingnginxnetworking

解决方案


推荐阅读