要在404错误页面中返回nginx的版本号,可以在nginx的配置文件中使用error_page指令来实现。以下是具体的步骤:

  1. 打开nginx的配置文件。通常位于/etc/nginx/nginx.conf或/usr/local/nginx/conf/nginx.conf。

  2. 在http块中添加如下代码:

http {
    ...
    error_page 404 /404.html;
    location = /404.html {
        internal;
        return 404 "<html><body><h1>404 Not Found</h1><p>Nginx Version: $nginx_version</p></body></html>";
    }
    ...
}
  1. 保存并关闭配置文件。

  2. 重新加载nginx的配置文件。

sudo nginx -t     # 检查配置文件语法是否正确
sudo systemctl reload nginx    # 重新加载配置文件

现在,当访问不存在的页面时,nginx会返回一个包含版本号的404错误页面。

nginx怎么关闭404时返回版本号

原文地址: https://www.cveoy.top/t/topic/i4Nr 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录