Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
HarryQu
V2EX  ›  Linux

Nginx 404 页面位于哪里 ?

  •  
  •   HarryQu · Dec 14, 2018 · 3524 views
    This topic created in 2738 days ago, the information mentioned may be changed or developed.

    最近在折腾 Nginx , 想找到这个 404 页面在那里 !

    上述的 404 页面并不在 /usr/share/nginx/html 当中

    /usr/share/nginx/html 中的 404 页面是这样的 :

    在 linux 中执行命令,搜索 nginx/1.12.2,并没有找到这个文件

     find / -xdev -type f -print0 | xargs -0 grep -H "nginx/1.12.2"
    

    因此 ,这个文件在哪里呢 ?

    11 replies    2018-12-15 11:17:30 +08:00
    msg7086
        3
    msg7086  
       Dec 14, 2018   ❤️ 1
    为了效率。这种常见的返回页面还要靠磁盘文件的话效率太低了。写进源代码一把梭。要修改的话直接改源码重新编译即可。
    HarryQu
        4
    HarryQu  
    OP
       Dec 14, 2018
    @greenskinmonster 原来不是直接写在 html 文件里的呀....
    HarryQu
        5
    HarryQu  
    OP
       Dec 14, 2018
    @msg7086 原来如此 , Thanks
    460881773
        6
    460881773  
       Dec 14, 2018
    你可以自定义 404 页面跳转啊不一定要 重新编译源码
    HarryQu
        7
    HarryQu  
    OP
       Dec 14, 2018
    @460881773 因为没有在 /usr/share/nginx/html 下发现这个文件,所以好奇想知道这个文件的路径在哪里。
    liyer
        8
    liyer  
       Dec 14, 2018
    创建个 404 丢进去就行了
    sparkssssssss
        9
    sparkssssssss  
       Dec 14, 2018
    这个 404 是没有实体页面的吧,nginx 返回 4xx 5xx 都是这个界面,
    Hardrain
        10
    Hardrain  
       Dec 15, 2018
    版本号估计会从 c 的 header(.h 文件)获得,而不是硬编码,所以你用 nginx/${版本号}去 grep 应该找不到。
    Hardrain
        11
    Hardrain  
       Dec 15, 2018   ❤️ 1
    是硬编码的,在$nginx_source_path/src/http/ngx_http_special_response.c 里面。

    ~ sed -n 132,137p $nginx_source_path/src/http/ngx_http_special_response.c

    static char ngx_http_error_404_page[] =
    "<html>" CRLF
    "<head><title>404 Not Found</title></head>" CRLF
    "<body>" CRLF
    "<center><h1>404 Not Found</h1></center>" CRLF
    ;

    至于页脚的版本号,应该与同一个文件中的 21,39 行有关
    static u_char ngx_http_error_full_tail[] =
    "<hr><center>" NGINX_VER "</center>" CRLF
    "</body>" CRLF
    "</html>" CRLF
    ;


    static u_char ngx_http_error_build_tail[] =
    "<hr><center>" NGINX_VER_BUILD "</center>" CRLF
    "</body>" CRLF
    "</html>" CRLF
    ;


    static u_char ngx_http_error_tail[] =
    "<hr><center>nginx</center>" CRLF
    "</body>" CRLF
    "</html>" CRLF
    ;

    以上结果由 nginx 1.15.7 源码得出。
    你可以下载其源码,修改这个文件后,用 nginx -V 获取原先的编译参数,再重新编译安装。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   885 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 20:43 · PVG 04:43 · LAX 13:43 · JFK 16:43
    ♥ Do have faith in what you're doing.